Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Remove the file in use

Remove the file in use

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mihai123
    wrote on last edited by
    #1

    Hello I have a little big problem that drive me crazy for 3 hours. I have a function that browse the content of a folder (with subfolders). After that operation is done I want to delete the folder. The function is recursive. All the files in the route folder are deleted ok. But I cannot delete the subFolders and their content. I use this code for retrieve information about files and folders:

    WIN32_FIND_DATA FindFileData;
    HANDLE hFind=INVALID_HANDLE_VALUE;
    hFind= FindFirstFile(aux,&FindFileData);

    FindNextFile(hFind, &FindFileData);

    I guess that it is us How can I remove the file/folder in use tag? I tried with

    delete &FindFileData

    it doesn't work. There must be a way out there ... I tried to delete the folder without browse it first and it works fine. The weird thing is that I can delete the files that are in the root.

    M C H 3 Replies Last reply
    0
    • M mihai123

      Hello I have a little big problem that drive me crazy for 3 hours. I have a function that browse the content of a folder (with subfolders). After that operation is done I want to delete the folder. The function is recursive. All the files in the route folder are deleted ok. But I cannot delete the subFolders and their content. I use this code for retrieve information about files and folders:

      WIN32_FIND_DATA FindFileData;
      HANDLE hFind=INVALID_HANDLE_VALUE;
      hFind= FindFirstFile(aux,&FindFileData);

      FindNextFile(hFind, &FindFileData);

      I guess that it is us How can I remove the file/folder in use tag? I tried with

      delete &FindFileData

      it doesn't work. There must be a way out there ... I tried to delete the folder without browse it first and it works fine. The weird thing is that I can delete the files that are in the root.

      M Offline
      M Offline
      Michael Schubert
      wrote on last edited by
      #2

      Did you use FindClose(hFind) ?

      1 Reply Last reply
      0
      • M mihai123

        Hello I have a little big problem that drive me crazy for 3 hours. I have a function that browse the content of a folder (with subfolders). After that operation is done I want to delete the folder. The function is recursive. All the files in the route folder are deleted ok. But I cannot delete the subFolders and their content. I use this code for retrieve information about files and folders:

        WIN32_FIND_DATA FindFileData;
        HANDLE hFind=INVALID_HANDLE_VALUE;
        hFind= FindFirstFile(aux,&FindFileData);

        FindNextFile(hFind, &FindFileData);

        I guess that it is us How can I remove the file/folder in use tag? I tried with

        delete &FindFileData

        it doesn't work. There must be a way out there ... I tried to delete the folder without browse it first and it works fine. The weird thing is that I can delete the files that are in the root.

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        Why don't you use

        DeleteFile(FindFileData.cFileName);

        ?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        1 Reply Last reply
        0
        • M mihai123

          Hello I have a little big problem that drive me crazy for 3 hours. I have a function that browse the content of a folder (with subfolders). After that operation is done I want to delete the folder. The function is recursive. All the files in the route folder are deleted ok. But I cannot delete the subFolders and their content. I use this code for retrieve information about files and folders:

          WIN32_FIND_DATA FindFileData;
          HANDLE hFind=INVALID_HANDLE_VALUE;
          hFind= FindFirstFile(aux,&FindFileData);

          FindNextFile(hFind, &FindFileData);

          I guess that it is us How can I remove the file/folder in use tag? I tried with

          delete &FindFileData

          it doesn't work. There must be a way out there ... I tried to delete the folder without browse it first and it works fine. The weird thing is that I can delete the files that are in the root.

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Can you use of _rmdir or SHFileOperation without this code?

          M 1 Reply Last reply
          0
          • H Hamid Taebi

            Can you use of _rmdir or SHFileOperation without this code?

            M Offline
            M Offline
            mihai123
            wrote on last edited by
            #5

            yes you can

            H 1 Reply Last reply
            0
            • M mihai123

              yes you can

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              And what result?

              M 1 Reply Last reply
              0
              • H Hamid Taebi

                And what result?

                M Offline
                M Offline
                mihai123
                wrote on last edited by
                #7

                I used this to erased a folder and it works

                SHFILEOPSTRUCT op;
                op.pFrom = szStoreFolder;
                //op.pTo = _T(""); //will be ignored
                op.wFunc = FO_DELETE;
                op.fFlags = FOF_SILENT | FOF_NOCONFIRMATION;
                op.fAnyOperationsAborted = false;
                op.hNameMappings = NULL;
                SHFileOperation(&op);

                only if you do not have the files in that folder in used... if you have that you should FindClose(handleFile) if you used previous a function that searched for file in that folder

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups