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 folder

delete a folder

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 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.
  • M Offline
    M Offline
    mihai123
    wrote on last edited by
    #1

    Hello, I'm trying to delete a folder with all subfolder that are in it. I found this structure on MSN

    typedef struct _SHFILEOPSTRUCT {
    HWND hwnd;
    UINT wFunc;
    LPCTSTR pFrom;
    LPCTSTR pTo;
    FILEOP_FLAGS fFlags;
    BOOL fAnyOperationsAborted;
    LPVOID hNameMappings;
    LPCTSTR lpszProgressTitle;
    } SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;

    try it like this

    SHFILEOPSTRUCT op;
    op.pFrom = _T("C:\\zipTest\\td10Updater\\*.*\0\0");
    //op.pTo = _T(""); //will be ignored
    op.wFunc = FO_DELETE;
    op.fFlags = FOF_SILENT;
    SHFileOperation(&op);

    what is wrong ?

    S M T H 4 Replies Last reply
    0
    • M mihai123

      Hello, I'm trying to delete a folder with all subfolder that are in it. I found this structure on MSN

      typedef struct _SHFILEOPSTRUCT {
      HWND hwnd;
      UINT wFunc;
      LPCTSTR pFrom;
      LPCTSTR pTo;
      FILEOP_FLAGS fFlags;
      BOOL fAnyOperationsAborted;
      LPVOID hNameMappings;
      LPCTSTR lpszProgressTitle;
      } SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;

      try it like this

      SHFILEOPSTRUCT op;
      op.pFrom = _T("C:\\zipTest\\td10Updater\\*.*\0\0");
      //op.pTo = _T(""); //will be ignored
      op.wFunc = FO_DELETE;
      op.fFlags = FOF_SILENT;
      SHFileOperation(&op);

      what is wrong ?

      S Offline
      S Offline
      sudhir_Kumar
      wrote on last edited by
      #2

      I think you can use code in this way. CString szFilePath = "D:\\DEVAPP\\TestApp\\Debug\\delete"; char aChars[MAX_PATH]; memset(aChars, '\0', MAX_PATH); strcpy(aChars, szFilePath.GetBuffer(1)); SHFILEOPSTRUCT op; op.hwnd = AfxGetApp()->GetMainWnd()->m_hWnd; op.pFrom = aChars; op.pTo = ""; op.wFunc = FO_DELETE; op.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI;; SHFileOperation(&op); :)

      Sudhir Kumar

      1 Reply Last reply
      0
      • M mihai123

        Hello, I'm trying to delete a folder with all subfolder that are in it. I found this structure on MSN

        typedef struct _SHFILEOPSTRUCT {
        HWND hwnd;
        UINT wFunc;
        LPCTSTR pFrom;
        LPCTSTR pTo;
        FILEOP_FLAGS fFlags;
        BOOL fAnyOperationsAborted;
        LPVOID hNameMappings;
        LPCTSTR lpszProgressTitle;
        } SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;

        try it like this

        SHFILEOPSTRUCT op;
        op.pFrom = _T("C:\\zipTest\\td10Updater\\*.*\0\0");
        //op.pTo = _T(""); //will be ignored
        op.wFunc = FO_DELETE;
        op.fFlags = FOF_SILENT;
        SHFileOperation(&op);

        what is wrong ?

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

        I found what was my problem prior to deletion I browse the folder with a recursive function. Then when I try to delete the subdirectory cannot be deleted, they are in use... I cannot understand why. For browsing I used

        WIN32_FIND_DATA FindFileData;
        HANDLE hFind

        and while condition

        while(FindNextFile(hFind, &FindFileData)!=0)

        S K 2 Replies Last reply
        0
        • M mihai123

          I found what was my problem prior to deletion I browse the folder with a recursive function. Then when I try to delete the subdirectory cannot be deleted, they are in use... I cannot understand why. For browsing I used

          WIN32_FIND_DATA FindFileData;
          HANDLE hFind

          and while condition

          while(FindNextFile(hFind, &FindFileData)!=0)

          S Offline
          S Offline
          sudhir_Kumar
          wrote on last edited by
          #4

          If you want to delete the folder with all sub folders then there is no need of recursive function. :)

          Sudhir Kumar

          M 1 Reply Last reply
          0
          • S sudhir_Kumar

            If you want to delete the folder with all sub folders then there is no need of recursive function. :)

            Sudhir Kumar

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

            I have a folder , I must browse this folder in order to make a 1:1 copy on a ftp server. Then I must delete this folder. For the browsing I use a recursive function. Now for some reason the subdirectory are still in use after the function ends and I cannot delete them....

            1 Reply Last reply
            0
            • M mihai123

              I found what was my problem prior to deletion I browse the folder with a recursive function. Then when I try to delete the subdirectory cannot be deleted, they are in use... I cannot understand why. For browsing I used

              WIN32_FIND_DATA FindFileData;
              HANDLE hFind

              and while condition

              while(FindNextFile(hFind, &FindFileData)!=0)

              K Offline
              K Offline
              krmed
              wrote on last edited by
              #6

              Perhaps you missed this from MSDN:

              When the search handle is not needed,
              close it by using the FindClose function.

              Since you haven't closed the handle, it's still in use. Hope that helps.

              Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

              1 Reply Last reply
              0
              • M mihai123

                Hello, I'm trying to delete a folder with all subfolder that are in it. I found this structure on MSN

                typedef struct _SHFILEOPSTRUCT {
                HWND hwnd;
                UINT wFunc;
                LPCTSTR pFrom;
                LPCTSTR pTo;
                FILEOP_FLAGS fFlags;
                BOOL fAnyOperationsAborted;
                LPVOID hNameMappings;
                LPCTSTR lpszProgressTitle;
                } SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;

                try it like this

                SHFILEOPSTRUCT op;
                op.pFrom = _T("C:\\zipTest\\td10Updater\\*.*\0\0");
                //op.pTo = _T(""); //will be ignored
                op.wFunc = FO_DELETE;
                op.fFlags = FOF_SILENT;
                SHFileOperation(&op);

                what is wrong ?

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                mihai123 wrote:

                SHFileOperation

                I always use this tested class :- http://www.codeproject.com/KB/shell/cshellfileop.aspx[^] when ever i want to do folder operations!

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                Never mind - my own stupidity is the source of every "problem" - Mixture

                cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>

                1 Reply Last reply
                0
                • M mihai123

                  Hello, I'm trying to delete a folder with all subfolder that are in it. I found this structure on MSN

                  typedef struct _SHFILEOPSTRUCT {
                  HWND hwnd;
                  UINT wFunc;
                  LPCTSTR pFrom;
                  LPCTSTR pTo;
                  FILEOP_FLAGS fFlags;
                  BOOL fAnyOperationsAborted;
                  LPVOID hNameMappings;
                  LPCTSTR lpszProgressTitle;
                  } SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;

                  try it like this

                  SHFILEOPSTRUCT op;
                  op.pFrom = _T("C:\\zipTest\\td10Updater\\*.*\0\0");
                  //op.pTo = _T(""); //will be ignored
                  op.wFunc = FO_DELETE;
                  op.fFlags = FOF_SILENT;
                  SHFileOperation(&op);

                  what is wrong ?

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

                  You can use of _rmdir.

                  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