实例:
①遍历文件夹并且计算文件夹个数
int iCount = 0;
CString strTempPath;
CString strFileName;
strTempPath = CBApp::getCurrModulePath() + _T("ini");
BOOL bWorking = finder.FindFile(strTempPath + _T("\\*.*"));
while (bWorking)
{
bWorking = finder.FindNextFile();
if(!finder.IsDots())
{
iCount++;
}
strFileName = finder.GetFilePath();
}
②删除非空的文件夹
bool CBSetting::DeleteDirectory(CString sPath)
{
CFileFind Finder;
CString sDir;
sDir.Format(_T("%s\\*.*"),sPath);
BOOL IsFinded = Finder.FindFile(sDir);
while (IsFinded)
{
IsFinded = Finder.FindNextFile();
if (!Finder.IsDots())
{
if (Finder.IsDirectory())
DeleteDirectory(Finder.GetFilePath());
else
DeleteFile(Finder.GetFilePath());
}
}
Finder.Close();
if(!RemoveDirectory(sPath))
{
return FALSE;
}
return TRUE;
}
③文件的删除和重命名
//删除预设文件
void CBSetting::deleteSettingFile(CString &sBoyeApp, CBObList &settingList, int iIndex)
{
CFileFind Finder;
CString sName;
sName.Format(_T("\\%d.ini"), iIndex);
CString strPath = sBoyeApp + sName;
if(Finder.FindFile(strPath))
{
DeleteFile(strPath);
}
else
return;
CString sOldName, sOldPath;
for (POSITION pos = settingList.FindIndex(iIndex); pos != NULL; iIndex ++)
{
settingList.GetNext(pos);
sOldName.Format(_T("\\%d.ini"), iIndex + 1);
sOldPath = sBoyeApp + sOldName;
if(Finder.FindFile(sOldPath))
CFile::Rename(sOldPath, strPath); //重命名文件
strPath = sOldPath;
}
}
④文件夹的删除和重命名
//删除对应的设备保存文件
void CBSetting::deleteDeviceFile(int iIndex)
{
CString sPath;
CString sOldPath;
CFileFind Finder;
sPath.Format(_T("ini\\%d"), iIndex);
sPath = CBApp::getCurrModulePath() + sPath;
if(Finder.FindFile(sPath))
{
DeleteFolder(sPath);
}
else
return;
for (POSITION pos = m_DeviceList.FindIndex(iIndex); pos != NULL; iIndex ++)
{
m_DeviceList.GetNext(pos);
sOldPath.Format(_T("ini\\%d"), iIndex + 1);
sOldPath = CBApp::getCurrModulePath() + sOldPath;
if(Finder.FindFile(sOldPath))
ReNameFolder(sOldPath, sPath);
sPath = sOldPath;
}
Finder.Close();
}
//删除文件夹
void CBSetting::DeleteFolder(CString sOldPath)
{
int nLength = sOldPath.GetLength();
TCHAR *pNewPath = new TCHAR[nLength+2];
memcpy(pNewPath, sOldPath.GetBuffer(), nLength * sizeof(TCHAR));
pNewPath[nLength] = '\0';
pNewPath[nLength+1] = '\0';
SHFILEOPSTRUCT FileOp;
Visual C++ MFC文件操作大全_理学_高等教育_教育专区 暂无评价0人阅读0次下载举报文档 Visual C++ MFC文件操作大全_理学_高等教育_教育专区。Windows程序设计...
MFC文件操作大全MFC文件操作大全隐藏>> MFC 文件操作大全分类: windows 开发 (2012-06-15 14:58) 1.创建文件夹 CreateDirectory(%%1,NULL); 2.创建文件 ...
MFC中的文件读写操作 26页 免费 MFC文件操作大全 79页 免费 MFC文件操作大全...MFC 文件操作 1.文件的查找当对一个文件操作时,如果不知道该文件是否存在,就要...
{ /*---用C语言写入文件--- FILE *pFile=fopen("www.txt","wb"); //... MFC文件操作大全 79页 2下载券 MFC 文件操作 暂无评价 5页 免费 MFC作业...
//文件然后都删除掉,再删除文件夹 十,复制文件 CopyFile(_T(路径),_T(路径... mfc总结 116页 免费 MFC个人总结 12页 4下载券 MFC文件操作大全 79页 2...
写文件: CFile f("c:\\1.txt",CFile::modeWriteCFile::modeCreate); f... MFC文件操作大全 79页 2下载券 MFC中树控件操作 6页 免费 SDK与MFC文件操作...
MFC中文件操作_电脑基础知识_IT/计算机_专业资料。C、C++、WinAPI、MFC等对... 中医养生知识大全 女人养生之道88份文档 2014全国高考状元联手分享状元笔记...
MFC文件操作大全 79页 5财富值 MFC文件操作2 4页 1财富值 Visual C++ MFC文件操作... 21页 免费 MFC中文件操作 暂无评价 12页 5财富值 使用MFC操作EXCEL...
要用到文件类的操作,看到这篇文章不错,特转载 计算机室如何管理自身所存放着的... MFC文件操作大全 79页 2下载券 MFC文件读写 5页 免费 MFC 文件操作 暂无...
热门文档