Archived

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

emreture

Getting contents of folder

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

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