查找指定目錄下的所有文件夾

void BrowseDir(CString& strDir)
{
//定義查找文件對象
CFileFind cff;
CString szDir = strDir;


//當為根目錄時,最右側為'\'
if(szDir.Right(1)!="\\")
szDir+="\\";
//所有文件
szDir += "*.*";


BOOL bResult = cff.FindFile(szDir);
while(bResult)
{
bResult = cff.FindNextFile();

if(cff.IsDirectory() && !cff.IsDots())
{
//用遞歸繼續往深一層查找
CString strPath = cff.GetFilePath();
/*自定義數組變量,存放查找到的目錄名與目錄路徑
sDirInfo[ldirCount].m_strFileName = cff.GetFileName();
sDirInfo[ldirCount].m_strInfo = strPath;*/

ldirCount++;
BrowseDir(strPath);
}
else if(!cff.IsDirectory() && !cff.IsDots())
{
}
}
cff.Close();
}

猜你喜欢

转载自blog.csdn.net/yuxiao1121/article/details/7404364