您的位置首页生活百科

请教调用 SHFileOperation 进行文件复制重命名的问题

请教调用 SHFileOperation 进行文件复制重命名的问题

#include//删除文件伍卖或者文件夹bool DeleteFile(TCHAR * lpszPath){ SHFILEOPSTRUCT FileOp={0}; FileOp.fFlags = FOF_ALLOWUNDO | //允许放回回收站 FOF_NOCONFIRMATION; //不出现确认对物差话框 FileOp.pFrom = lpszPath; FileOp.pTo = NULL; //一定要是NULL FileOp.wFunc = FO_DELETE; //删除操作 return SHFileOperation(&FileOp) == 0;}//复制文件或文件夹bool CopyFile(TCHAR *pTo,TCHAR *pFrom){ SHFILEOPSTRUCT FileOp={0}; FileOp.fFlags = FOF_NOCONFIRMATION| //不出现确认对话框 FOF_NOCONFIRMMKDIR //需要时直接创建一个文件夹,不需罩橘皮用户确定 |FOF_SIMPLEPROGRESS ; //进度条 FileOp.pFrom = pFrom; FileOp.pTo = pTo; FileOp.wFunc = FO_COPY; return SHFileOperation(&FileOp) == 0;}//移动文件或文件夹bool MoveFile(TCHAR *pTo,TCHAR *pFrom){ SHFILEOPSTRUCT FileOp={0}; FileOp.fFlags = FOF_NOCONFIRMATION| //不出现确认对话框 FOF_NOCONFIRMMKDIR ; //需要时直接创建一个文件夹,不需用户确定 FileOp.pFrom = pFrom; FileOp.pTo = pTo; FileOp.wFunc = FO_MOVE; return SHFileOperation(&FileOp) == 0; }//从命名文件或文件夹bool ReNameFile(TCHAR *pTo,TCHAR *pFrom){ SHFILEOPSTRUCT FileOp={0}; FileOp.fFlags = FOF_NOCONFIRMATION ; FileOp.pFrom = pFrom; FileOp.pTo = pTo; FileOp.wFunc = FO_RENAME; FileOp.hwnd= HWND_DESKTOP; return SHFileOperation(&FileOp)==0; }void CShfileopDlg::OnButton1() { // TODO: Add your control notification handler code here CopyFile(_T("c:\\two"),_T("c:\\123")); ReNameFile(_T("c:\\newtwo"),_T("c:\\123")); DeleteFile(_T("c:\\newtwo")); AfxMessageBox(_T("完成")); }