deleting a empty folder from a specified path
-
I want to delete a empty folder present at a specified path. I am using this code for doing this:- <pre> CString fol_Path = _T("C:\\Program Files\\New Folder"); if(_taccess(fol_Path, 0) != -1) { Attributes = GetFileAttributes(fol_Path); if(Attributes != 0xFFFFFFFF) { SetFileAttributes(fol_Path,FILE_ATTRIBUTE_NORMAL); _wunlink(fol_Path); } } </pre> but my _wunlink function is returning -1 value..... i am using unicode..... can anbody tel me how to do this..... thanks in advance
-
I want to delete a empty folder present at a specified path. I am using this code for doing this:- <pre> CString fol_Path = _T("C:\\Program Files\\New Folder"); if(_taccess(fol_Path, 0) != -1) { Attributes = GetFileAttributes(fol_Path); if(Attributes != 0xFFFFFFFF) { SetFileAttributes(fol_Path,FILE_ATTRIBUTE_NORMAL); _wunlink(fol_Path); } } </pre> but my _wunlink function is returning -1 value..... i am using unicode..... can anbody tel me how to do this..... thanks in advance
You're using a rather bizarre mixture of Win32, tchar and _UNICODE functions. I assume you have checked elsewhere that the folder you want to delete is empty, right? Also, you don't have to use
GetFileAttributes()
since you want to delete the folder anyway. Most importantly, check the return code fromSetFileAttributes()
withGetLastError()
. If that is successful, useRemoveDirectory()
and again check the return value withGetLastError()
.