16,471
社区成员
发帖
与我相关
我的任务
分享
void GetFolderObj(LPCTSTR szDir, CAtlString strRelative, BOOL bIncludeHiden,CAtlList<CAtlString>& strDir, CAtlList<CAtlString>& strFile)//枚举该文件夹下的所有文件和文件夹 设定条件为包含隐藏或者不隐藏
{
CAtlString strkkk(szDir);
strkkk += _T("\\*.*");
WIN32_FIND_DATA fileInfo; //取得文件大小!!
HANDLE hFind = FindFirstFile( strkkk.GetString() ,&fileInfo );
if ( INVALID_HANDLE_VALUE != hFind )
{
do{
CString strPath;
if ( 0 == ( fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN && !bIncludeHiden)
{
continue;
}
if ( StrCmp (fileInfo.cFileName, _T(".") ) != 0 && StrCmp (fileInfo.cFileName, _T("..")) != 0 )
{
if(!strRelative.IsEmpty())
{
strPath = strRelative;
strPath += _T("\\");
strPath += fileInfo.cFileName;
}
else
strPath = fileInfo.cFileName;//是文件
strFile.AddTail(strPath);
}
}
else if ( ( fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN && !bIncludeHiden)
{
continue;
}
if ( StrCmp (fileInfo.cFileName, _T(".") ) != 0 && StrCmp (fileInfo.cFileName, _T("..")) != 0 )
{
CAtlString sss;
if(!strRelative.IsEmpty())
{
sss = strRelative;
sss += _T("\\");
sss += fileInfo.cFileName;
}else
sss = fileInfo.cFileName;
strDir.AddTail(sss);
strPath.Format(_T("%s\\%s"),szDir ,fileInfo.cFileName);
GetFolderObj(strPath, sss, bIncludeHiden, strDir, strFile);
}
}
} while ( ::FindNextFile( hFind, &fileInfo ) );
::FindClose( hFind );
}
return ;
}