Just had a quick look in my snippets directory. Found this. This uses Microsoft's Win32 API directly:
vector<CStdString> filenames;
CStdString directoryPath("C:\\foo\\bar\\baz\\*");
WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(directoryPath, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
filenames.push_back(FindFileData.cFileName);
} while (FindNextFile(hFind, &FindFileData));
FindClose(hFind);
}
This gives you a vector with all filenames in a directory. It only works on Windows of course.
João Augusto noted in an answer:
Don't forget to check after FindClose(hFind)
for:
DWORD dwError = GetLastError();
if (dwError != ERROR_NO_MORE_FILES)
{
// Error happened
}
It's especially important if scanning on a network.