SomeUser
SomeUser

Reputation: 2041

How to get list of folders in this folder?

How to get list of folders in this folder?

Upvotes: 7

Views: 17237

Answers (4)

ephemient
ephemient

Reputation: 204994

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

Upvotes: 10

Vector Maniac
Vector Maniac

Reputation: 95

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

Upvotes: 1

John Weldon
John Weldon

Reputation: 40789

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

Upvotes: 8

Robert Greiner
Robert Greiner

Reputation: 29762

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

Upvotes: 3

Related Questions