VC文件操作
重命名文件:
注意: 该操作对文件夹一样有效!
CFileFind Finder;CString sOldPath = _T("D:\tt.txt");CString strPath = _T("D:\tt.txt.BAK");if(Finder.FindFile(sOldPath)){AfxMessageBox(_T("重命名完成"));CFile::Rename(sOldPath, strPath); //重命名文件}elseAfxMessageBox(_T("无法重命名,文件不存在!"));
FindFile确认文件是否存在.
但是如何检测是否有权限?
删除文件:
CString strPath = _T("D:\tt.txt");if(Finder.FindFile(strPath)){DeleteFile(strPath);AfxMessageBox(_T("删除完成"));}elseAfxMessageBox(_T("无法删除,源文件不存在!"));