Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

emreture

Getting contents of folder

This topic is 5169 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

how can i get contents of a folder? i''m using mingw compiler under Win32, it should be something like FindFirst(...) & FindNext(...). but i couldn''t figure out.
What we do in life, echoes in eternity!

Share this post


Link to post
Share on other sites
Advertisement

int FindFiles(std::vector<std::string> &_array, const char *_extension, const char *_path)
{
// Get the current directory.

char curDir[512];
strcpy(curDir, getcwd(curDir, 127));

// Change directory to given path

chdir(_path);

// Find the first file matching the given extension

struct _finddata_t item;
intptr_t hFile = _findfirst(_extension, &item);

// None found.

if(hFile == -1)
{
chdir( curDir );
return 0;
}

// Loop to find the rest of the items matching the extensions.

do
{
std::string name = _path;
name += ''/'';
name += item.name;
_array.push_back(name);
}
while(!_findnext( hFile, &item ));

// Done.

_findclose(hFile);

// Change back to our starting directory.

chdir( curDir );

// Return how many are in the vector.

return (int)_array.size();
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!