#include <iostream>
#include <string>
#include <list>
#include <io.h> //_findfirst, etc
#include <direct.h> //_chdir
int main()
{
struct _finddata_t c_file;
long hFile;
std::list<std::string> fileList; //czy tablica, czy co tam wolisz
_chdir("D:/windows/system32");
if((hFile = _findfirst("*.dll", &c_file )) != -1L)
{
do
{
if(!(_A_SUBDIR & c_file.attrib)) //plik
//gdybys jako filtr podał "*"
//funkcja zwracała by też katalogi
//możesz pominiąć ten warunek
{
fileList.push_back(std::string(c_file.name));
}
}
while(!_findnext(hFile, &c_file));
_findclose(hFile);
}
//mamy listę to coś z nią zróbmy :)
for(std::list<std::string>::iterator it = fileList.begin(); it != fileList.end(); it++)
{
std::cout << *it << std::endl;
}
return 0;
}
PS
struktura finddata zwraca Ci więcej informacji o pliku niż samą nazwę.
struct _finddata32_t {
unsigned attrib;
__time32_t time_create; /* -1 for FAT file systems */
__time32_t time_access; /* -1 for FAT file systems */
__time32_t time_write;
_fsize_t size;
char name[260];
};