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. Delete folder MFC code

Delete folder MFC code

Scheduled Pinned Locked Moved C / C++ / MFC
6 Posts 5 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.
  • D Offline
    D Offline
    deeps_cute
    wrote on last edited by
    #1

    I want to delete a folder which is have a content. WIN32_FIND_DATA FindFileData; HANDLE hHandle ; int complt; char FileName[100]; strcpy(FileName,""); char rpath[]="C:\\bootfdr"; char Path[]="C:\\bootfdr\\"; SetCurrentDirectory(Path); hHandle=FindFirstFile("*.*",&FindFileData); if(hHandle == INVALID_HANDLE_VALUE) MessageBox("Path NotFound"); else { while(complt) { strcpy(FileName,Path); strcat(FileName,FindFileData.cFileName); DeleteFile(FileName); complt=FindNextFile(hHandle,&FindFileData); } } FindClose(hHandle); if(RemoveDirectory(rpath)) MessageBox("Deleted"); else MessageBox("Sorry i cant"); am use this code but only files inside the folder is deleted.but not the folder is deleted

    Arise Awake Stop Not Till ur Goal is Reached.

    H N T 3 Replies Last reply
    0
    • D deeps_cute

      I want to delete a folder which is have a content. WIN32_FIND_DATA FindFileData; HANDLE hHandle ; int complt; char FileName[100]; strcpy(FileName,""); char rpath[]="C:\\bootfdr"; char Path[]="C:\\bootfdr\\"; SetCurrentDirectory(Path); hHandle=FindFirstFile("*.*",&FindFileData); if(hHandle == INVALID_HANDLE_VALUE) MessageBox("Path NotFound"); else { while(complt) { strcpy(FileName,Path); strcat(FileName,FindFileData.cFileName); DeleteFile(FileName); complt=FindNextFile(hHandle,&FindFileData); } } FindClose(hHandle); if(RemoveDirectory(rpath)) MessageBox("Deleted"); else MessageBox("Sorry i cant"); am use this code but only files inside the folder is deleted.but not the folder is deleted

      Arise Awake Stop Not Till ur Goal is Reached.

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

      Use of SHFileOperation


      WhiteSky


      1 Reply Last reply
      0
      • D deeps_cute

        I want to delete a folder which is have a content. WIN32_FIND_DATA FindFileData; HANDLE hHandle ; int complt; char FileName[100]; strcpy(FileName,""); char rpath[]="C:\\bootfdr"; char Path[]="C:\\bootfdr\\"; SetCurrentDirectory(Path); hHandle=FindFirstFile("*.*",&FindFileData); if(hHandle == INVALID_HANDLE_VALUE) MessageBox("Path NotFound"); else { while(complt) { strcpy(FileName,Path); strcat(FileName,FindFileData.cFileName); DeleteFile(FileName); complt=FindNextFile(hHandle,&FindFileData); } } FindClose(hHandle); if(RemoveDirectory(rpath)) MessageBox("Deleted"); else MessageBox("Sorry i cant"); am use this code but only files inside the folder is deleted.but not the folder is deleted

        Arise Awake Stop Not Till ur Goal is Reached.

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        use SHFileOperation instead of RemoveDirectory. This function will delete the directory event if there are contents in that folder.

        nave

        P 1 Reply Last reply
        0
        • D deeps_cute

          I want to delete a folder which is have a content. WIN32_FIND_DATA FindFileData; HANDLE hHandle ; int complt; char FileName[100]; strcpy(FileName,""); char rpath[]="C:\\bootfdr"; char Path[]="C:\\bootfdr\\"; SetCurrentDirectory(Path); hHandle=FindFirstFile("*.*",&FindFileData); if(hHandle == INVALID_HANDLE_VALUE) MessageBox("Path NotFound"); else { while(complt) { strcpy(FileName,Path); strcat(FileName,FindFileData.cFileName); DeleteFile(FileName); complt=FindNextFile(hHandle,&FindFileData); } } FindClose(hHandle); if(RemoveDirectory(rpath)) MessageBox("Deleted"); else MessageBox("Sorry i cant"); am use this code but only files inside the folder is deleted.but not the folder is deleted

          Arise Awake Stop Not Till ur Goal is Reached.

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          Mr. deeps_cute, you've been asking question over this board for long time now... will you once comply to the posting guidelines[^] ??? I especially talk about the <pre></pre> tags, but some other points apply to you too


          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          1 Reply Last reply
          0
          • N Naveen

            use SHFileOperation instead of RemoveDirectory. This function will delete the directory event if there are contents in that folder.

            nave

            P Offline
            P Offline
            platso_588
            wrote on last edited by
            #5

            I like to Delete folder in any case even if other applications or other users are accessing the same folder. Forcefully i like to delete the Folder. I receive Error 32 when the function SHFileOperation(). Can any one tell me how can i acheive this.

            N 1 Reply Last reply
            0
            • P platso_588

              I like to Delete folder in any case even if other applications or other users are accessing the same folder. Forcefully i like to delete the Folder. I receive Error 32 when the function SHFileOperation(). Can any one tell me how can i acheive this.

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              yeah. if any process has kept any files opened from that folder. you will not be able to delete it. refer this article Listing Used Files[^]

              nave [My Articles] [My Blog]

              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