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 directory

delete directory

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
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.
  • I Offline
    I Offline
    includeh10
    wrote on last edited by
    #1

    how to delete a directory which has sub-directories and files directly? thanks includeh10

    A A R T 4 Replies Last reply
    0
    • I includeh10

      how to delete a directory which has sub-directories and files directly? thanks includeh10

      A Offline
      A Offline
      anju
      wrote on last edited by
      #2

      Hi, See this article in CP.. http://www.codeproject.com/file/removefiles.asp all the best:rose: anju

      I 1 Reply Last reply
      0
      • A anju

        Hi, See this article in CP.. http://www.codeproject.com/file/removefiles.asp all the best:rose: anju

        I Offline
        I Offline
        includeh10
        wrote on last edited by
        #3

        it is still to delete files first in a loop ... :rose: includeh10

        1 Reply Last reply
        0
        • I includeh10

          how to delete a directory which has sub-directories and files directly? thanks includeh10

          A Offline
          A Offline
          Abin
          wrote on last edited by
          #4

          http://www.codeproject.com/file/CFileManip.asp[^] Use this function: static BOOL DelTree(LPCTSTR lpSource, BOOL bHidePrompt = TRUE);

          1 Reply Last reply
          0
          • I includeh10

            how to delete a directory which has sub-directories and files directly? thanks includeh10

            R Offline
            R Offline
            Rickard Andersson20
            wrote on last edited by
            #5

            ::SHFileOperation() Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

            1 Reply Last reply
            0
            • I includeh10

              how to delete a directory which has sub-directories and files directly? thanks includeh10

              T Offline
              T Offline
              TomKat
              wrote on last edited by
              #6

              BOOL ClearDirectory(const char *path, BOOL recurs, BOOL deldirs) { if(!path) return FALSE; char xpath[512]=""; strcpy(xpath,path); HANDLE hFile; WIN32_FIND_DATA findData; BOOL Go=TRUE; char fullp[500]=""; char pattern[500]=""; if(xpath[strlen(xpath)-1]!='\\') strcat(xpath,"\\"); if(!IsDirectory(xpath)) return FALSE; strcpy(pattern,xpath); strcat(pattern,"*.*"); hFile=FindFirstFile(pattern,&findData); while((hFile!=INVALID_HANDLE_VALUE)&&(Go)) { if((strcmp(findData.cFileName,".")!=0)&&(strcmp(findData.cFileName,"..")!=0)) { strcpy(fullp,""); sprintf(fullp,"%s%s",xpath,findData.cFileName); if(IsDirectory(fullp)) { ClearDirectory(fullp,recurs,deldirs); strcat(fullp,"\\"); if(deldirs) RemoveDirectory(fullp); } else { SetFileAttributes(fullp,128); DeleteFile(fullp); } } ZeroMemory((void*)&findData,sizeof(findData)); Go=FindNextFile(hFile,&findData); } FindClose(hFile); if(deldirs) RemoveDirectory(xpath); return TRUE; } be nice an rate me ! be cool I am the mighty keeper of the book on knowledge . Contact me to get your copy .

              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