I’m unable to delete a folder in Windows with the following code:
SHFILEOPSTRUCT shfo = {
NULL,
FO_DELETE,
path,
NULL,
FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION,
FALSE,
NULL,
NULL };
SHFileOperation(&shfo);
I need to use SHFileOperation instead of RemoveDirectory because I need to delete non-empty folders.
However, the function fails even if the value in path points to an empty local folder with full control of Everyone user, is double-null terminated (as requested by documentation), has no system, hidden or read only attribute…
Unfortunately the function does not return an error code (returns zero if successful, or nonzero otherwise) and calling GetLastError returns ERROR_SUCCESS…
Where is the error?
Solved…
The
pathvariable wasn’t actually double-null terminated because I usedwcscpy_sthat fills the string buffer (that I had previously filled with zeros) with the 0xFD value after the null char…