How to get list of folders in this folder?
+3
A:
You can use Boost
Or, if you don't want Boost you can check out this thread where alternative options are discussed. http://www.gamedev.net/community/forums/topic.asp?topic_id=523375
Robert Greiner
2010-02-10 19:55:32
+7
A:
FindFirstFileEx+FindExSearchLimitToDirectories.
WIN32_FIND_DATA fi;
HANDLE h = FindFirstFileEx(
dir,
FindExInfoStandard,
&fi,
FindExSearchLimitToDirectories,
NULL,
0);
if (h != INVALID_HANDLE_VALUE) {
do {
printf("%s\n", fi.cFileName);
} while (FindNextFile(h, &fi));
FindClose(h);
}
ephemient
2010-02-10 19:56:24
Nice... I didn't know about FindExSearchLimitToDirectories +1
John Weldon
2010-02-10 20:12:02
FindExSearchLimitToDirectories is not really a reliable solution. It is an advisory flag only. For example on my Windows XP Pro SP3 system with NTFS it does not have any effect. See: http://stackoverflow.com/questions/2248911/file-system-support-for-findfirstfileex-limit-to-directories
Ash
2010-02-16 04:32:39
I would expect that somebody would follow the links and read the documentation (which says "If the file system does not support directory filtering, this flag is silently ignored.") before using this code. Unreasonable expectation?
ephemient
2010-02-16 06:32:03
+1
A:
If you can't use .NET & Managed code, you can go through the win32 api's
Here is an example that you can modify to only get Folders.
(Basically the following check:)
...
TCHAR szDir = _T("c:\\"); // or wherever.
HANDLE hFind = FindFirstFile(szDir, &ffd);
...
do {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// your code on 'ffd'
}
} while (FindNextFile(hFind, &ffd) != 0);
John Weldon
2010-02-10 20:02:36
+1
A:
For best portability, use the boost filesystem library. Use opendir()/readdir() and friends for UNIX based systems.
Vector Maniac
2010-02-11 02:20:30
A:
I simply cannot get FindExSearchLimitToDirectories to work as expected, even on Windows 7. Has anyone actually seen this work as advertised?
Mark
2010-06-17 12:50:04