How to get list of folders in this folder?

16,508

Solution 1

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);

Solution 2

FindFirstFileEx+FindExSearchLimitToDirectories.

WIN32_FIND_DATA fi;
HANDLE h = FindFirstFileEx(
        dir,
        FindExInfoStandard,
        &fi,
        FindExSearchLimitToDirectories,
        NULL,
        0);
if (h != INVALID_HANDLE_VALUE) {
    do {
        if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 
            printf("%s\n", fi.cFileName);
    } while (FindNextFile(h, &fi));
    FindClose(h);
}

Solution 3

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

Solution 4

For best portability, use the boost filesystem library. Use opendir()/readdir() and friends for UNIX based systems.

Share:
16,508
SomeUser
Author by

SomeUser

About me

Updated on June 12, 2022

Comments

  • SomeUser
    SomeUser almost 2 years

    How to get list of folders in this folder?