开发者

Unable to delete a folder with SHFileOperation

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 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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜