我将d盘下的一个文件夹MoveFile到e盘下的一个文件夹中:CString strExit,strNew;
strExit = "d:\\begin\\test directory";
strNew = "e:\\target\\test directory";if(!MoveFile(strExit,strNew))
return;为什么MoveFile返回总是错误的,GetLastError值为5,也就是ERROR_ACCESS_DENIED?难道不同盘符之间,不能movefile文件夹?
strExit = "d:\\begin\\test directory";
strNew = "e:\\target\\test directory";if(!MoveFile(strExit,strNew))
return;为什么MoveFile返回总是错误的,GetLastError值为5,也就是ERROR_ACCESS_DENIED?难道不同盘符之间,不能movefile文件夹?
LPCTSTR lpExistingFileName, // pointer to the name of the existing file
LPCTSTR lpNewFileName // pointer to the new name for the file
);
移动是文件,不是目录,所以错误
CString StrSourceFolder="E:\\VC++";
CString StrDestFolder="D:\\";
char SourceFolder[MAX_PATH+1]="";
strcpy(SourceFolder,StrSourceFolder);
char TargetFolder[MAX_PATH+1]="";
strcpy(TargetFolder,StrDestFolder);
SHFILEOPSTRUCT lpFile;
lpFile.hwnd=GetSafeHwnd();
lpFile.wFunc=FO_COPY;
lpFile.pFrom=SourceFolder;
lpFile.pTo=TargetFolder;
lpFile.fFlags=FOF_ALLOWUNDO;
lpFile.fAnyOperationsAborted=FALSE;
lpFile.hNameMappings=NULL;
lpFile.lpszProgressTitle=NULL;
int ReturnValue=SHFileOperation(&lpFile);
if(ReturnValue==0)
{
if(lpFile.fAnyOperationsAborted==TRUE)
MessageBox("复制文件夹的操作被取消","信息提示",MB_OK+MB_ICONWARNING);
else
MessageBox("复制文件夹操作成功","信息提示",MB_OK+MB_ICONWARNING);
}
else
MessageBox("复制文件夹操作失败","信息提示",MB_OK+MB_ICONEXCLAMATION);