环境:win7 32 日文版,vs2005
错误代码:
SHFILEOPSTRUCT fileOp;
memset(&fileOp, 0, sizeof(SHFILEOPSTRUCT));
fileOp.wFunc = FO_DELETE;
fileOp.fFlags = ( FOF_NOCONFIRMATION);
fileOp.lpszProgressTitle = msgTitle;
char path2[MAX_PATH];
strcpy_s(path2, sizeof(path2), "H:\\IMG\\*.*");
fileOp.pFrom = path2;
if(SHFileOperation(&fileOp) != 0){ // ERROR
CString msg;
CString msgTitle;
msg.Format(_T("删除失败"));
MessageBox(msg, msgTitle, MB_ICONSTOP | MB_OK);
return;
}
上面代码中SHFileOperation返回124,并且删除失败
但是如果改成
fileOp.pFrom = "H:\\IMG\\*.*";
则返回0,并且删除成功
百度,网上说pFrom的文件列表需以\0\0结尾,而文件之间以\0结尾,故如果是变量路径,需改为
strcpy_s(path2, sizeof(path2), "H:\\IMG\\*.*");
memset(path2+strlen(path2), 0, MAX_PATH-strlen(path2));
fileOp.pFrom = path2;
参考:
http://bbs.eyuyan.com/simple/?t92127.html
http://bbs.csdn.net/topics/50439584
http://bbs.csdn.net/topics/50081174