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


Getting contents of folder

Recommended Posts

emreture    122
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
DrEvil    1148

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


// 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.

std::string name = _path;
name += ''/'';
name +=;
while(!_findnext( hFile, &item ));

// Done.


// 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