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?
The path
variable wasn't actually double-null terminated because I used wcscpy_s
that fills the string buffer (that I had previously filled with zeros) with the 0xFD value after the null char...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With