溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

MFC第二課 文件類型使用技巧

發(fā)布時間:2020-07-18 14:02:45 來源:網(wǎng)絡(luò) 閱讀:431 作者:fengyuzaitu 欄目:編程語言

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

PathFileExists(CString strFileName)

2)文件夾
創(chuàng)建文件夾:CreateDirectory()
刪除文件夾:ReMoveDirectory()

3)文件路徑的存儲問題
例如:test\\test.cpp文件
如果需要保存在一個CString類型或者
一個char數(shù)組,需要添加多一個\
如下:
char* pdbName = "test\\\test.cpp"
否則運行的查看顯示如下:
test\test.cpp

注意:實際上可以通過/,來避免上述問題的產(chǎn)生

修改文件名稱
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
??? {//轉(zhuǎn)換文件名稱大小寫
????? if(!finder.IsDots())
????? {
??????? CString strOldName = finder.GetFilePath();
??????? CString strNewName = finder.GetFilePath();
??????? strNewName.MakeLower();
??????? CFile::Rename(strOldName,strNewName);
????? }
?
??????? }
??? }
}
?
調(diào)用過程:
??? CString strDir = _T("d:/log");
??? TransferName(strDir);
其中的關(guān)鍵點:
if(!finder.IsDots())
表示當(dāng)前的工作目錄

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI