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. RemoveDirectoryW()

RemoveDirectoryW()

Scheduled Pinned Locked Moved C / C++ / MFC
testingbeta-testinghelpquestion
10 Posts 3 Posters 1 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.
  • P Offline
    P Offline
    p_1960
    wrote on last edited by
    #1

    Hi, im using RemoveDirectoryW() ...the problem is.. RemoveDirectoryW(L"c:\\test\\testing"); the above deletes the folder testing but when.... the path to delete is present in two LPCWSTR"s then how can i add them ie... LPCWSTR lpPath1=L"c:\\temp\\folder1\\"; LPCWSTR lpPath2=L"testing\\tester"; i need to pass the combination of the above to RemoveDirectoryW()(finally i should delete tester).....Please let me know how can i do this....

    M D 2 Replies Last reply
    0
    • P p_1960

      Hi, im using RemoveDirectoryW() ...the problem is.. RemoveDirectoryW(L"c:\\test\\testing"); the above deletes the folder testing but when.... the path to delete is present in two LPCWSTR"s then how can i add them ie... LPCWSTR lpPath1=L"c:\\temp\\folder1\\"; LPCWSTR lpPath2=L"testing\\tester"; i need to pass the combination of the above to RemoveDirectoryW()(finally i should delete tester).....Please let me know how can i do this....

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

      Not sure what you're trying to do. Do you want to delete a directory that has sub-directories? Could you re-phrase your request a bit?

      P 1 Reply Last reply
      0
      • M Michael Schubert

        Not sure what you're trying to do. Do you want to delete a directory that has sub-directories? Could you re-phrase your request a bit?

        P Offline
        P Offline
        p_1960
        wrote on last edited by
        #3

        Yes i will ..... I need to delete a folder named "Test" which is present in the folder TEMP(Environment variable)... im able to get the path of TEMP using... WCHAR buffer[1042]={'\0'}; DWORD size=1042; ::GetEnvironmentVariableW(L"TEMP",(LPWSTR)buffer,size); CString csPath; csPath=buffer; im able to get the path of TEMP in csPath... now i have to delete the folder Test which is inside that TEMP folder.... When i use RemoveDirectoryW() i need to pass the path(in LPCWSTR) to Test folder....so please help me to attain this....

        M 1 Reply Last reply
        0
        • P p_1960

          Hi, im using RemoveDirectoryW() ...the problem is.. RemoveDirectoryW(L"c:\\test\\testing"); the above deletes the folder testing but when.... the path to delete is present in two LPCWSTR"s then how can i add them ie... LPCWSTR lpPath1=L"c:\\temp\\folder1\\"; LPCWSTR lpPath2=L"testing\\tester"; i need to pass the combination of the above to RemoveDirectoryW()(finally i should delete tester).....Please let me know how can i do this....

          D Offline
          D Offline
          Dominik Reichl
          wrote on last edited by
          #4

          To concatenate the two strings, you could use something like this:

          LPCWSTR lpPath1=L"c:\\temp\\folder1\\";
          LPCWSTR lpPath2=L"testing\\tester";

          std::basic_string<WCHAR> strPath = lpPath1;
          strPath += lpPath2;

          RemoveDirectoryW(strPath.c_str());

          This requires a #include <string>. Note that I'd recommend generic text mappings (with _T, etc.) instead of just using Unicode directly.


          Too many passwords to remember? Try KeePass Password Safe!

          P 1 Reply Last reply
          0
          • P p_1960

            Yes i will ..... I need to delete a folder named "Test" which is present in the folder TEMP(Environment variable)... im able to get the path of TEMP using... WCHAR buffer[1042]={'\0'}; DWORD size=1042; ::GetEnvironmentVariableW(L"TEMP",(LPWSTR)buffer,size); CString csPath; csPath=buffer; im able to get the path of TEMP in csPath... now i have to delete the folder Test which is inside that TEMP folder.... When i use RemoveDirectoryW() i need to pass the path(in LPCWSTR) to Test folder....so please help me to attain this....

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

            See Dominik's reply below. You also have to consider that RemoveDirectory will only delete empty directories. You might consider using SHFileOperation, here's an example: http://bobmoore.mvps.org/Win32/w32tip28.htm[^]

            1 Reply Last reply
            0
            • D Dominik Reichl

              To concatenate the two strings, you could use something like this:

              LPCWSTR lpPath1=L"c:\\temp\\folder1\\";
              LPCWSTR lpPath2=L"testing\\tester";

              std::basic_string<WCHAR> strPath = lpPath1;
              strPath += lpPath2;

              RemoveDirectoryW(strPath.c_str());

              This requires a #include <string>. Note that I'd recommend generic text mappings (with _T, etc.) instead of just using Unicode directly.


              Too many passwords to remember? Try KeePass Password Safe!

              P Offline
              P Offline
              p_1960
              wrote on last edited by
              #6

              Thanks for ur support.... May i know how to achieve this if lpPath1 is a Cstring.....

              D 1 Reply Last reply
              0
              • P p_1960

                Thanks for ur support.... May i know how to achieve this if lpPath1 is a Cstring.....

                D Offline
                D Offline
                Dominik Reichl
                wrote on last edited by
                #7

                CString strPath1 = _T("c:\\temp\\folder1\\");
                CString strPath2 = _T("testing\\tester");

                CString strPath = strPath1 + strPath2;

                RemoveDirectory(strPath);


                Too many passwords to remember? Try KeePass Password Safe!

                P 1 Reply Last reply
                0
                • D Dominik Reichl

                  CString strPath1 = _T("c:\\temp\\folder1\\");
                  CString strPath2 = _T("testing\\tester");

                  CString strPath = strPath1 + strPath2;

                  RemoveDirectory(strPath);


                  Too many passwords to remember? Try KeePass Password Safe!

                  P Offline
                  P Offline
                  p_1960
                  wrote on last edited by
                  #8

                  Sorry i mean to say if only lpPath1 is Cstring and lpPath2 is LPCWSTR then how can i add them and pass to RemoveDirectoryW() Please let me know.....

                  D 1 Reply Last reply
                  0
                  • P p_1960

                    Sorry i mean to say if only lpPath1 is Cstring and lpPath2 is LPCWSTR then how can i add them and pass to RemoveDirectoryW() Please let me know.....

                    D Offline
                    D Offline
                    Dominik Reichl
                    wrote on last edited by
                    #9

                    If you're compiling in Unicode mode, it's basically just the same:

                    CString strPath1 = _T("c:\\temp\\folder1\\");
                    LPCWSTR lpPath2 = L"testing\\tester";

                    CString strPath = strPath1 + lpPath2;

                    RemoveDirectoryW(strPath);


                    Too many passwords to remember? Try KeePass Password Safe!

                    P 1 Reply Last reply
                    0
                    • D Dominik Reichl

                      If you're compiling in Unicode mode, it's basically just the same:

                      CString strPath1 = _T("c:\\temp\\folder1\\");
                      LPCWSTR lpPath2 = L"testing\\tester";

                      CString strPath = strPath1 + lpPath2;

                      RemoveDirectoryW(strPath);


                      Too many passwords to remember? Try KeePass Password Safe!

                      P Offline
                      P Offline
                      p_1960
                      wrote on last edited by
                      #10

                      Hi, sorry it"s deleting thanks.....

                      modified on Saturday, March 21, 2009 9:59 AM

                      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