Rempli la liste des fichiers d'un repertoire et de ses sous-repertoire récusivement.
1 void scan( const std::wstring& path, const std::wstring& filter, std::vector<std::wstring> &list )
2 {
3 WIN32_FIND_DATA FindFileData;
4 HANDLE hFind;
5
6 std::wstring tmp = path + filter;
7 hFind = ::FindFirstFile( tmp.c_str(), &FindFileData);
8
9 if ( hFind == INVALID_HANDLE_VALUE )
10 {
11 throw Exception();
12 return ;
13 }
14
15 do
16 {
17 std::wstring filename = FindFileData.cFileName;
18 if ( filename == TEXT(".") )
19 continue;
20 if ( filename == TEXT("..") )
21 continue;
22 if ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
23 scan( path + filename + TEXT("\\"), filter, list );
24 else
25 list.push_back( path + filename );
26
27 } while ( ::FindNextFile(hFind, &FindFileData) != 0 );
28 }
29
30 //Utilisation
31 std::map<std::wstring> list;
32 scan( TEXT("C:\\"), TEXT("*"), list ) ;
Pages : 1