VC文件操作

VC文件操作

重命名文件:

注意: 该操作对文件夹一样有效!

  1. CFileFind Finder;
  2. CString sOldPath = _T("D:\tt.txt");
  3. CString strPath = _T("D:\tt.txt.BAK");
  4. if(Finder.FindFile(sOldPath))
  5. {
  6. AfxMessageBox(_T("重命名完成"));
  7. CFile::Rename(sOldPath, strPath); //重命名文件
  8. }else
  9. AfxMessageBox(_T("无法重命名,文件不存在!"));

FindFile确认文件是否存在.
但是如何检测是否有权限?

删除文件:

  1. CString strPath = _T("D:\tt.txt");
  2. if(Finder.FindFile(strPath))
  3. {
  4. DeleteFile(strPath);
  5. AfxMessageBox(_T("删除完成"));
  6. }
  7. else
  8. AfxMessageBox(_T("无法删除,源文件不存在!"));




原文地址:https://www.cnblogs.com/skyhuangdan/p/5486362.html