char FromBuf[]= "f:\\*.*\0";//如果是上面的就可以,换成下面的就不可以,为什么??
//CString strFrom = "f:\\*.*"; LPTSTR FromBuf = (LPTSTR)(LPCTSTR)strFrom;
charToBuf[]= "c:\\";
SHFILEOPSTRUCT Op;
Op.hwnd = NULL;
Op.wFunc = FO_COPY;
Op.pFrom = FromBuf;//FromBuf;
Op.pTo = ToBuf;
Op.fFlags = FOF_NOCONFIRMATION | FOF_RENAMEONCOLLISION;
Op.fAnyOperationsAborted = FALSE;
Op.hNameMappings = NULL;
Op.lpszProgressTitle = NULL;
if(SHFileOperation(&Op) == 0)
MessageBox("复制完毕","提示",MB_OK|MB_ICONINFORMATION);
上面的原因应该是字符串的原因,因为字符串最后一个字符是NULL,那么SHFileOperation认为它后面还是一个文件(SHFileOperation以NULL分隔多个文件),就会向后找文件。
解决方法:
CString strFrom = "f:\\*.*";
int size = sizeof(strFrom);
CCHAR FromBuff[size + 1];
memcpy(FromBuff, strFrom, size);
FromBuff[size] = 0x0;//如果FromBuff长度大于Size时,一定要这样
LPTSTR FromBuf = (LPTSTR)(LPCTSTR)strFrom;