在MFC中,使用CFileFind类,可以枚举一行掘掘个目录下的所有文件和子目录。
示例:
void ListFolder(const CString & sPath){
CFileFind ff
BOOL bFound = 档核ff.FindFile(sPath + "\\*.*")
while(bFound)
{
bFound = ff.FindNextFile()
if(ff.IsDirectory()) //是目录
{
if(!ff.IsDots()) 散裂//不是本级目录或父目录(.和..)
ListFolder(ff.GetFilePath()) //递归子目录
}
else
{
AfxMessageBox("文件:" + ff.GetFilePath())
}
}
ff.Close()
}
void CXXXDlg::SearchFiles(CString strMusicFolder){
CFileFind ff
strMusicFolder += _T("\\")
局扒喊 strMusicFolder += _T("桐野*.*")
BOOL res = ff.FindFile(strMusicFolder)
此世while (res)
{
res = ff.FindNextFile()
if (!ff.IsDirectory() && !ff.IsDots())
{
afxMessageBox(ff.GetFilePath())
}
}
ff.Close()
}
int i=0CString strPath[10]
CFileFind ff
BOOL ret = ff.FindFile("d:\\temp\\*.DAT")
while(ret)
{
ret = ff.FindNextFile()
strPath[i++] = ff.GetFileName()
}
ff.Close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)