FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Dobbs M-Dev
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
March 01, 2003

Adapting Win32 Enumeration APIs to STL Iterator Concepts

(Page 8 of 13)
Adapting Win32 Enumeration APIs to STL Iterator Concepts

Listing 5 Using the FindFile API to list directories



void list_sub_directories(char const *dir)
{
  WIN32_FIND_DATA findData;
  TCHAR           szFind[_MAX_PATH];
  HANDLE          hFind;

  lstrcpy(szFind, dir);
  lstrcat(szFind, "\\*.*");

  hFind = FindFirstFile(szFind, &findData);

  if(hFind != INVALID_HANDLE_VALUE)
  {
    do
    {
      if( lstrcmpi(findData.cFileName, ".") == 0 ||
          lstrcmpi(findData.cFileName, "..") == 0)
      {
        // Ignore dots
      }
      else if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      {
        // Show subdirectories
        printf( "%s\n", findData.cFileName);
      }

    } while(FindNextFile(hFind, &findData));

    FindClose(hFind);
  }
}

int main(int argc, char **argv)
{
  char szDir[_MAX_PATH];

  GetCurrentDirectory(_MAX_PATH, szDir);

  list_sub_directories(szDir);

  return 0;
}
Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK