■フォルダー内のファイル一覧(サブディレクトリーもお探す)
void CTheView::OnTest()
{
CStringArray astrFiles;
GetFileList("C:\\TEMP", // 探すフォルダー
TRUE, // TRUE:サブディレクトリも探す FALSE:探さない
astrFiles ); // 結果の配列
for( int i=0; i<astrFiles.GetSize(); i++) {
AfxMessageBox( astrFiles[i] );
}
}
void CTheView::GetFileList(LPCTSTR lpFolder, BOOL bSubFolder, CStringArray& astrFiles )
{
CFileFind find;
CString sFolder;
sFolder.Format("%s\\*.*", lpFolder);
if (!find.FindFile(sFolder)) return;
while( find.FindNextFile()) {
if (!find.IsDots()) {
if (find.IsDirectory() && bSubFolder != FALSE ) { // サブディレクトリも探す場合
this->GetFileList(find.GetFilePath(), bSubFolder , astrFiles ); // 再帰呼出
}
else {
if( !find.IsDirectory() ) {
astrFiles.Add( find.GetFilePath() );
}
}
}
}
}
| Copyright (C) CRIMSON Systems |
 |
|
|