Jump to content
  • Advertisement
Sign in to follow this  

Getting file-names in a directory

This topic is 4580 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'm searching for a method/algorithm or a way how to get every filename in a specified folder. I used the search function, but the only thing I found was "outdatet" because dirent.h doesnt exists (anymore?). Also searched articles on gamedev but found nothing that could help me. At the moment I'm using ms visual c++ 2005. thanks in advance

Share this post

Link to post
Share on other sites
A short question:
My source looks like this:

BOOL xyz::GetFilesFromDirectory(char* Path){
string searchPath = Path;
HANDLE fileSearcher;
BOOL worked = FALSE;
LPWIN32_FIND_DATA DataInformation = NULL;

fileSearcher = FindFirstFile(Path, DataInformation);

if(fileSearcher != INVALID_HANDLE_VALUE && DataInformation != NULL){
worked = TRUE;

while(FindNextFile(fileSearcher, DataInformation)){

return worked;

The path is:

The problem is that he doesnt find any file.
In the documentaition is written that you can use wildcars for files and some other stuff.
Tried with the path:
But if I use this path I always get an unhandled exception.

Any suggestions?

Share this post

Link to post
Share on other sites
You need to allocate your DataInformation variable, not pass a NULL pointer.

WIN32_FIND_DATA theFind;

hFind = FindFirstFile(Path,&theFind);
return false;

do {
// Add filename to list
} while(FindNextFile(hFind,&theFind);

FindClose(hFind); // Don't forget this!

You want to pass "Data\\Maps\\*.dat" as your path. If you pass "Data\\Maps", then there won't be any files that match that path, so FindFirstFile() returns INVALID_HANDLE_VALUE, and DataInformation is never filled. When you pass "Data\\Maps\\*.dat", DataInformation gets used, and you get an access violation as Win32 tries to write to a NULL pointer.

[Edited by - Evil Steve on March 5, 2006 1:00:55 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!