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 a directory

Delete a directory

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
5 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.
  • S Offline
    S Offline
    see me
    wrote on last edited by
    #1

    If there is api to delete a directory????:) yours faithfully ajeesh

    C H D N 4 Replies Last reply
    0
    • S see me

      If there is api to delete a directory????:) yours faithfully ajeesh

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      rmdir[^]


      Cédric Moonen Software developer
      Charting control

      1 Reply Last reply
      0
      • S see me

        If there is api to delete a directory????:) yours faithfully ajeesh

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

        RemoveDirectory_**


        **_

        whitesky


        1 Reply Last reply
        0
        • S see me

          If there is api to delete a directory????:) yours faithfully ajeesh

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          SHFileOperation()


          "The largest fire starts but with the smallest spark." - David Crow

          "Judge not by the eye but by the heart." - Native American Proverb

          1 Reply Last reply
          0
          • S see me

            If there is api to delete a directory????:) yours faithfully ajeesh

            N Offline
            N Offline
            neilsolent
            wrote on last edited by
            #5

            This will delete a directory and all of its contents: static BOOL DeleteDirectoryPath(const CString& path) { // Function to delete a directory, including the case where // files and sub-directories exist. Also deletes the name specified, // if it is actually a file. WIN32_FIND_DATA find; HANDLE findHandle; CString file, filePattern; DWORD fileAttrib, err; filePattern = path + "\\*.*"; findHandle = FindFirstFile(filePattern, &find); while (findHandle != INVALID_HANDLE_VALUE) { if ((strcmp(find.cFileName, ".") != 0) && (strcmp(find.cFileName, "..") != 0)) { file.Format("%s\\%s", path, find.cFileName); if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (! DeleteDirectoryPath(file)) { return FALSE; } } else { SetFileAttributes(file, FILE_ATTRIBUTE_NORMAL); //Prevents some deletion failures if (! DeleteFile(file)) { return FALSE; } } } if (! FindNextFile(findHandle, &find)) break; } FindClose(findHandle); fileAttrib = GetFileAttributes(path); if (fileAttrib == 0xFFFFFFFF) { err = GetLastError(); if (err == ERROR_FILE_NOT_FOUND) { return TRUE; } else { return FALSE; } } else if (fileAttrib & FILE_ATTRIBUTE_DIRECTORY) { if (! RemoveDirectory(path)) { return FALSE; } } else { SetFileAttributes(path, FILE_ATTRIBUTE_NORMAL); //Prevents some deletion failures if (! DeleteFile(path)) { return FALSE; } } return TRUE; } cheers, Neil

            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