Advertisement

Enumerating Folders

Started by August 03, 2001 12:08 PM
2 comments, last by stefu 23 years, 6 months ago
  

// Find first file

WIN32_FIND_DATA FindFileData;
HANDLE h = FindFirstFile( "Tracks\\*.*", &FindFileData );

// Then repeat for next files

FindNextFile(h,&FindFileData)

  
This enumerates all files, but how can I enumerate only folders? Each track has own subfolder and I need to get list of tracks.
FindFirstFileEx. It allows special searching parameters, and one of those is directories. Check is out in MSDN or MSVC help.
Advertisement
MSDN says FindFirstFileEx is not supported in Windows 9x!
It doesn''t compile.

But hey, I can check file attributes (_WIN32_FIND_DATA.DWORD dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY).

By the way, FindFirstFile/FindNextFile is an iterator, so use it like this:
for (HANDLE hFind = FindFirstFile (szSpec, &wfd); GetLastError() != ERROR_NO_MORE_FILES; FindNextFile (hFind, &wfd) ) {
// Analyze wfd for each file
}
FindClose (hFind);
VK

This topic is closed to new replies.

Advertisement