Jump to content
  • Advertisement
Sign in to follow this  

Searching a folder

This topic is 5466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post

Link to post
Share on other sites
Its simple, check out FindFirstFile and FindNextFile.

Heres some code:
WIN32_FIND_DATA		FileData;
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...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!