开发者

How to get list of folders in this folder?

How to g开发者_C百科et list of folders in this folder?


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


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜