解説
フォルダ内に存在する指定した拡張子を持った全てのファイル名を取得する。
得られる結果はファイル名順に並んでいるわけではない。そのため必要に応じて
並べ替える必要がある。
使用例
bool GetAllFileFromFolder(CStringArray& astrFile,CString strFolder,CString strExtension="*.*");
//フォルダ内にあるjpgファイルを列挙
void test(void)
{
int i;
CString strText;
CStringArray astrFiles;
GetAllFileFromFolder(astrFiles,"c:\\","*.jpg");
for(i = 0; i < astrFiles.GetSize(); i++)
{
strText += astrFiles[i];
strText += "\n";
}
AfxMessageBox(strText);
}
//
// フォルダ内のファイルを列挙
//
bool GetAllFileFromFolder(CStringArray& astrFile,CString strFolder,CString strExtension/*="*.*"*/)
{
BOOL bContinue;
CFileFind cFind;
CString strFile;
astrFile.RemoveAll();
if(strFolder.Right(1) != "\\")
strFolder += "\\";
strFolder += strExtension;
bContinue = cFind.FindFile(strFolder);
while(bContinue)
{
bContinue = cFind.FindNextFile();
if(cFind.IsDirectory() == FALSE)
{
strFile = cFind.GetFilePath();
astrFile.Add(strFile);
}
}
return true;
}







