ファイル列挙 2

/**
* ファイル列挙
*/
void enumFiles( LPCWSTR pszDirPath, CStringArray& files )
{
// フィルタの設定
CStringW strFilter;
strFilter.Format( L"%s\\*", pszDirPath );

// 検索開始
WIN32_FIND_DATA stFindData;
HANDLE hFind = ::FindFirstFileW( strFilter, &stFindData );
if ( hFind == INVALID_HANDLE_VALUE ) return;

do
{
if ( ( 0 == ::lstrcmp( stFindData.cFileName, L"." ) ) ||
( 0 == ::lstrcmp( stFindData.cFileName, L".." ) ) ) continue;

if ( stFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
CStringW strPath;
strPath.Format( L"%s\\%s", pszDirPath, stFindData.cFileName );

// 再帰
enumFiles( strPath, files );
}
else
{
CStringW strPath;
strPath.Format( L"%s\\%s", pszDirPath, stFindData.cFileName );

// 追加
files.Add( strPath );
}
}
while ( ::FindNextFileW( hFind, &stFindData ) );

// 検索終了
::FindClose( hFind );
}
最終更新:2012年04月24日 08:56
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。