# Searching a folder

## Recommended Posts

Kris2456    100
Hi, i was just wondering is there a function or something that tells you what files are in a folder. So instead of having to type in a file for loading into the source. My program will search the data folder and load all of the files that are in it. Thx

##### Share on other sites
uavfun    744
On Windows you can use FindFirstFile and FindNextFile to get a list of files.

Kris2456    100
perfect
thx

##### Share on other sites
coldacid    755
You might also want to check out the Boost Filesystem library for iterating through directories.

##### Share on other sites
Prozak    898
Its simple, check out FindFirstFile and FindNextFile.

Heres some code:
WIN32_FIND_DATA		FileData;HANDLE			hFile;String			found;hFile = FindFirstFile("Data\\*.bmp", &FileData);if ( INVALID_HANDLE_VALUE == hFile ) { return false; };found = FileData.cFileName; //To find out if a returned file name is in fact a folder do:bool isFolder = (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);// To find the next file do:if ( 0 == FindNextFile(hFile, &FileData ) ) { return false; };// Now its just a question of looping

Hope it helped...