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. Weird windows problem

Weird windows problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebugging
5 Posts 3 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 have a weird problem regarding the deleting of a folder. I'm trying to delete a folder using this code

                        TCHAR exeDirectory\[MAX\_PATH\];
    		GetCurrentDirectory(sizeof(exeDirecotry) - 1, exeDirectory);
    		CString szStoreFolder;
                        szStoreFolder.Format(\_T("%s\\\\td10"),exeDirectory); 
                                    ......
                                 SHFILEOPSTRUCT op;
    			op.pFrom = szFolderName;
    			//op.pTo = \_T("");		//will be ignored
    			op.wFunc = FO\_DELETE;
    			op.fFlags = FOF\_SILENT | FOF\_NOCONFIRMATION;
    			op.fAnyOperationsAborted = false;
    			op.hNameMappings = NULL;
    			int er= SHFileOperation(&op);
    			\_tprintf(\_T("Eroare %d "),er);
    

    The problem is that it doesn't work every time. It depends on the exeDirectory name and on the folder name (the folder that I'm trying to delete) For instance if the exeDirectory is TEST and the folder name is Td10 it doesn't work. If the exeDirectory is ZIP_OPTION and the folder name TD10 it works. If the exe folder is TEST and the folder name is TemporaryData it works but now for the ZIP_OPTION folder it dosn't work. I made a debug and the szFolder contains the correct path. I've got the error 1026. I tried to take the path with CFileFinder but still the same problem appears. I tried also to take the short folder name but it the same. I do not know what to do. Any help or advice would be appreciate Tnx

    M M K 3 Replies Last reply
    0
    • M mihai123

      Hello, I have a weird problem regarding the deleting of a folder. I'm trying to delete a folder using this code

                          TCHAR exeDirectory\[MAX\_PATH\];
      		GetCurrentDirectory(sizeof(exeDirecotry) - 1, exeDirectory);
      		CString szStoreFolder;
                          szStoreFolder.Format(\_T("%s\\\\td10"),exeDirectory); 
                                      ......
                                   SHFILEOPSTRUCT op;
      			op.pFrom = szFolderName;
      			//op.pTo = \_T("");		//will be ignored
      			op.wFunc = FO\_DELETE;
      			op.fFlags = FOF\_SILENT | FOF\_NOCONFIRMATION;
      			op.fAnyOperationsAborted = false;
      			op.hNameMappings = NULL;
      			int er= SHFileOperation(&op);
      			\_tprintf(\_T("Eroare %d "),er);
      

      The problem is that it doesn't work every time. It depends on the exeDirectory name and on the folder name (the folder that I'm trying to delete) For instance if the exeDirectory is TEST and the folder name is Td10 it doesn't work. If the exeDirectory is ZIP_OPTION and the folder name TD10 it works. If the exe folder is TEST and the folder name is TemporaryData it works but now for the ZIP_OPTION folder it dosn't work. I made a debug and the szFolder contains the correct path. I've got the error 1026. I tried to take the path with CFileFinder but still the same problem appears. I tried also to take the short folder name but it the same. I do not know what to do. Any help or advice would be appreciate Tnx

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

      Why are you using GetCurrentDirectory()? I don't know the rest of your code but there is a chance that the current directory changes after a recursive deletion with SHFileOperation or elsewhere in your code. Also, you are mentioning 3 different variables for the path: "szStoreFolder", "szFolder" and "szFolderName". Very confusing.

      1 Reply Last reply
      0
      • M mihai123

        Hello, I have a weird problem regarding the deleting of a folder. I'm trying to delete a folder using this code

                            TCHAR exeDirectory\[MAX\_PATH\];
        		GetCurrentDirectory(sizeof(exeDirecotry) - 1, exeDirectory);
        		CString szStoreFolder;
                            szStoreFolder.Format(\_T("%s\\\\td10"),exeDirectory); 
                                        ......
                                     SHFILEOPSTRUCT op;
        			op.pFrom = szFolderName;
        			//op.pTo = \_T("");		//will be ignored
        			op.wFunc = FO\_DELETE;
        			op.fFlags = FOF\_SILENT | FOF\_NOCONFIRMATION;
        			op.fAnyOperationsAborted = false;
        			op.hNameMappings = NULL;
        			int er= SHFileOperation(&op);
        			\_tprintf(\_T("Eroare %d "),er);
        

        The problem is that it doesn't work every time. It depends on the exeDirectory name and on the folder name (the folder that I'm trying to delete) For instance if the exeDirectory is TEST and the folder name is Td10 it doesn't work. If the exeDirectory is ZIP_OPTION and the folder name TD10 it works. If the exe folder is TEST and the folder name is TemporaryData it works but now for the ZIP_OPTION folder it dosn't work. I made a debug and the szFolder contains the correct path. I've got the error 1026. I tried to take the path with CFileFinder but still the same problem appears. I tried also to take the short folder name but it the same. I do not know what to do. Any help or advice would be appreciate Tnx

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

        problem solved You should use the relative name to the current folder and the short name of the folder DOES NOT WORK WITH LONG FOLDER NAME.

        1 Reply Last reply
        0
        • M mihai123

          Hello, I have a weird problem regarding the deleting of a folder. I'm trying to delete a folder using this code

                              TCHAR exeDirectory\[MAX\_PATH\];
          		GetCurrentDirectory(sizeof(exeDirecotry) - 1, exeDirectory);
          		CString szStoreFolder;
                              szStoreFolder.Format(\_T("%s\\\\td10"),exeDirectory); 
                                          ......
                                       SHFILEOPSTRUCT op;
          			op.pFrom = szFolderName;
          			//op.pTo = \_T("");		//will be ignored
          			op.wFunc = FO\_DELETE;
          			op.fFlags = FOF\_SILENT | FOF\_NOCONFIRMATION;
          			op.fAnyOperationsAborted = false;
          			op.hNameMappings = NULL;
          			int er= SHFileOperation(&op);
          			\_tprintf(\_T("Eroare %d "),er);
          

          The problem is that it doesn't work every time. It depends on the exeDirectory name and on the folder name (the folder that I'm trying to delete) For instance if the exeDirectory is TEST and the folder name is Td10 it doesn't work. If the exeDirectory is ZIP_OPTION and the folder name TD10 it works. If the exe folder is TEST and the folder name is TemporaryData it works but now for the ZIP_OPTION folder it dosn't work. I made a debug and the szFolder contains the correct path. I've got the error 1026. I tried to take the path with CFileFinder but still the same problem appears. I tried also to take the short folder name but it the same. I do not know what to do. Any help or advice would be appreciate Tnx

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

          I think your problem may actually be that your szStoreFolder is terminated only with a single NULL character and it should be terminated with double NULL characters. MSDN[^]says to use fully qualified path names (not relative) - this allows the files/folders to be moved to the recycle bin. 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

          M 1 Reply Last reply
          0
          • K krmed

            I think your problem may actually be that your szStoreFolder is terminated only with a single NULL character and it should be terminated with double NULL characters. MSDN[^]says to use fully qualified path names (not relative) - this allows the files/folders to be moved to the recycle bin. 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

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

            Maybe that is true. I tried to build the string like there but the code didn't delete the folder. Anyway I want to permanently delete the folder so it is ok like it is now. The problem was related with full path and full name of folder that I want to delete (for the folder name you must use the short name not the long one). Anyway that was a weird problem because in 50%-60% of case the code was working fine, without any changes.

            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