SHFileOperation and win2000
-
the following code works great on win98 but on win2000 i get the error Cannot Delete File: Cannot read from the source file or disk. The program resides on a network drive and is shared between the 98 and 2000 machine. I have debugged dirname and it is the same on both machines. thank you for any help. wsprintf(dirname,"%s\\%s%s",Td.Dest_Dir,GetSubDir(),"\0"); HANDLE hFind = FindFirstFile(dirname,&FindFileData); if(hFind != INVALID_HANDLE_VALUE && FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){ SHFILEOPSTRUCT shf; memset(&shf,0,sizeof(shf)); shf.hwnd = selcompany::GetSafeHwnd(); shf.wFunc = FO_DELETE; shf.pFrom = dirname; shf.pTo = "\0\0";//NULL; shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; shf.fAnyOperationsAborted = FALSE; shf.hNameMappings = NULL; shf.lpszProgressTitle = " "; if(SHFileOperation(&shf)==0){ //////////////////////clear vars reset window } }else{ ////////////not valid ..... }
-
the following code works great on win98 but on win2000 i get the error Cannot Delete File: Cannot read from the source file or disk. The program resides on a network drive and is shared between the 98 and 2000 machine. I have debugged dirname and it is the same on both machines. thank you for any help. wsprintf(dirname,"%s\\%s%s",Td.Dest_Dir,GetSubDir(),"\0"); HANDLE hFind = FindFirstFile(dirname,&FindFileData); if(hFind != INVALID_HANDLE_VALUE && FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){ SHFILEOPSTRUCT shf; memset(&shf,0,sizeof(shf)); shf.hwnd = selcompany::GetSafeHwnd(); shf.wFunc = FO_DELETE; shf.pFrom = dirname; shf.pTo = "\0\0";//NULL; shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; shf.fAnyOperationsAborted = FALSE; shf.hNameMappings = NULL; shf.lpszProgressTitle = " "; if(SHFileOperation(&shf)==0){ //////////////////////clear vars reset window } }else{ ////////////not valid ..... }
Forget about it, this anwer was obviously wrong.
shf.lpszProgressTitle = " ";
I don't konw if this is the reason of your problem, but I think it should be
shf.lpszProgressTitle = L" ";
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
the following code works great on win98 but on win2000 i get the error Cannot Delete File: Cannot read from the source file or disk. The program resides on a network drive and is shared between the 98 and 2000 machine. I have debugged dirname and it is the same on both machines. thank you for any help. wsprintf(dirname,"%s\\%s%s",Td.Dest_Dir,GetSubDir(),"\0"); HANDLE hFind = FindFirstFile(dirname,&FindFileData); if(hFind != INVALID_HANDLE_VALUE && FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){ SHFILEOPSTRUCT shf; memset(&shf,0,sizeof(shf)); shf.hwnd = selcompany::GetSafeHwnd(); shf.wFunc = FO_DELETE; shf.pFrom = dirname; shf.pTo = "\0\0";//NULL; shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; shf.fAnyOperationsAborted = FALSE; shf.hNameMappings = NULL; shf.lpszProgressTitle = " "; if(SHFileOperation(&shf)==0){ //////////////////////clear vars reset window } }else{ ////////////not valid ..... }
Do you have WRITE permissions on the share? Nish
Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.
-
the following code works great on win98 but on win2000 i get the error Cannot Delete File: Cannot read from the source file or disk. The program resides on a network drive and is shared between the 98 and 2000 machine. I have debugged dirname and it is the same on both machines. thank you for any help. wsprintf(dirname,"%s\\%s%s",Td.Dest_Dir,GetSubDir(),"\0"); HANDLE hFind = FindFirstFile(dirname,&FindFileData); if(hFind != INVALID_HANDLE_VALUE && FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){ SHFILEOPSTRUCT shf; memset(&shf,0,sizeof(shf)); shf.hwnd = selcompany::GetSafeHwnd(); shf.wFunc = FO_DELETE; shf.pFrom = dirname; shf.pTo = "\0\0";//NULL; shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; shf.fAnyOperationsAborted = FALSE; shf.hNameMappings = NULL; shf.lpszProgressTitle = " "; if(SHFileOperation(&shf)==0){ //////////////////////clear vars reset window } }else{ ////////////not valid ..... }
You cannot sprintf a null character using %s, because "\0" looks the same as "", which is no characters at all. You'll need to put the extra null char there yourself - I usually zero out the entire buffer beforehand so I don't have to worry about finding the exact end of the string and tacking on an extra 0. --Mike-- Buy me stuff! Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Big fan of Alyson Hannigan and Jamie Salé.
-
You cannot sprintf a null character using %s, because "\0" looks the same as "", which is no characters at all. You'll need to put the extra null char there yourself - I usually zero out the entire buffer beforehand so I don't have to worry about finding the exact end of the string and tacking on an extra 0. --Mike-- Buy me stuff! Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Big fan of Alyson Hannigan and Jamie Salé.