码迷,mamicode.com
首页 > 其他好文 > 详细

VC文件操作

时间:2016-05-13 10:11:52      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

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("无法删除,源文件不存在!"));




VC文件操作

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!