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