温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MFC第二课 文件类型使用技巧

发布时间:2020-07-18 14:02:45 来源:网络 阅读:419 作者:fengyuzaitu 栏目:编程语言

1)文件/文件夹是否存在
添加头文件:
#include <shlwapi.h>
#pragma comment(lib,"Shlwapi.lib")

PathFileExists(CString strFileName)

2)文件夹
创建文件夹:CreateDirectory()
删除文件夹:ReMoveDirectory()

3)文件路径的存储问题
例如:test\\test.cpp文件
如果需要保存在一个CString类型或者
一个char数组,需要添加多一个\
如下:
char* pdbName = "test\\\test.cpp"
否则运行的查看显示如下:
test\test.cpp

注意:实际上可以通过/,来避免上述问题的产生

修改文件名称
CString strOldName= _T("D:\\old.txt");
CString strNewName= _T("D:\\new.txt");
CFile::Rename(strOldName,strNewName);

需求说明:文件夹中的文件一律替换成小写

void TransferName(CString strDirPath)  
{  
    CFileFind finder;
    CString path;
    path.Format(_T("%s/*.*"),strDirPath);
    BOOL bWorking = finder.FindFile(path);
    while(bWorking)
  {
        bWorking = finder.FindNextFile();
        if(finder.IsDirectory() && !finder.IsDots())
    {//处理文件夹
            TransferName(finder.GetFilePath()); //递归文件夹
        }
        else
    {//转换文件名称大小写
      if(!finder.IsDots())
      {
        CString strOldName = finder.GetFilePath();
        CString strNewName = finder.GetFilePath();
        strNewName.MakeLower();
        CFile::Rename(strOldName,strNewName);
      }
 
        }
    }
}
 
调用过程:
    CString strDir = _T("d:/log");
    TransferName(strDir);
其中的关键点:
if(!finder.IsDots())
表示当前的工作目录

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI