views:

489

answers:

2

Would anyone know what the Win32 equivalent of opendir is (or if it even exists) ? Obviously I could use FindFirstFile(Ex) with FindNextFile, but appending * to the path seems like such a hackish way to do it.

A: 

I believe you can use CreateFile with FILE_FLAG_BACKUP_SEMANTICS and then BackupRead to read directory data, but I'm not sure what format the data is actually in. Also, you would need to be running as a user with the SE_BACKUP_NAME privilege enabled, so this is not really suitable in a general purpose application.

Greg Hewgill
+3  A: 

FindFirstFile and FindNextFile are the appropriate Win32 APIs. Assuming you're writing C++ code, as a portable alternative you could consider using directory_iterator from the Boost Filesystem library (which is implemented on Windows using FindFirstFile and FindNextFile).

ChrisN