指定目录及其子目录下的查找指定文件
void BrowseFile(CString& strDir, CString& strFile, CString& Ext)
{
//定义查找文件对象
CFileFind cff;
CString szDir = strDir;
//当为根目录时,最右侧为'\'
if(szDir.Right(1)!="\\")
szDir+="\\";
//所有类型文件
szDir += strFile+"*";
BOOL bResult = cff.FindFile(szDir);
while(bResult)
{
bResult = cff.FindNextFile();
if(cff.IsDirectory() && !cff.IsDots())
{
}
else if(!cff.IsDirectory() && !cff.IsDots())
{
//查到符合文件名条件的文件
CString name = cff.GetFileName();
CString ext = name.Right(4);
ext.MakeLower();
if(ext == Ext)
{
//查到符合后缀名条件的文件,写入自定义数组变量中
int len = name.GetLength();
sFileInfo[lfileCount].m_strFileName = name;
CString path = cff.GetFilePath();
path.Delete(path.GetLength()-len,len);
sFileInfo[lfileCount].m_strInfo = path;
lfileCount++;
}
}
}
cff.Close();
}
{
//定义查找文件对象
CFileFind cff;
CString szDir = strDir;
//当为根目录时,最右侧为'\'
if(szDir.Right(1)!="\\")
szDir+="\\";
//所有类型文件
szDir += strFile+"*";
BOOL bResult = cff.FindFile(szDir);
while(bResult)
{
bResult = cff.FindNextFile();
if(cff.IsDirectory() && !cff.IsDots())
{
}
else if(!cff.IsDirectory() && !cff.IsDots())
{
//查到符合文件名条件的文件
CString name = cff.GetFileName();
CString ext = name.Right(4);
ext.MakeLower();
if(ext == Ext)
{
//查到符合后缀名条件的文件,写入自定义数组变量中
int len = name.GetLength();
sFileInfo[lfileCount].m_strFileName = name;
CString path = cff.GetFilePath();
path.Delete(path.GetLength()-len,len);
sFileInfo[lfileCount].m_strInfo = path;
lfileCount++;
}
}
}
cff.Close();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.