c++, List all files, dirent.h on Windows
Asked Answered
S

3

5

in C++, what would be the best way to list all files of a directory on Windows?

On Linux or on Windows using gcc (e.g. MingW) this is easy possible with dirent.h, but what's the best way to do it on Windows when dirent.h is not available (e.g. Visual Studio)?

Should I force people do add a freely available implementation of dirent.h to their Visual Studio? Or should I write an alternative code for reading the files? If this, what would be the best code to do so?

Thanks.

Sinatra answered 30/4, 2011 at 8:35 Comment(0)
F
2

Something like Boost Filesystem would work across all of those situations.

Fireboard answered 30/4, 2011 at 8:40 Comment(2)
Requiring them to add Boost to their VS environment.Amylo
@unapersson yes, they would. It doesn't seem like there's any problem with that.Fireboard
O
5

dirent.h is a POSIX header. On Windows you use the Find*File*() functions in the Win32 API.

Olag answered 30/4, 2011 at 8:39 Comment(3)
+1 because FindFirstFile+FindNextFile is the best way to find files on Windows without extra abstraction layers.Masjid
I wonder, if it's POSIX (dirent.h ), shouldn't it be accessed on Windows too? (because windows is almost posix compliant)Rna
@gekannt: Windows is nowhere near POSIX-compliant.Olag
F
2

Something like Boost Filesystem would work across all of those situations.

Fireboard answered 30/4, 2011 at 8:40 Comment(2)
Requiring them to add Boost to their VS environment.Amylo
@unapersson yes, they would. It doesn't seem like there's any problem with that.Fireboard
R
1

To add to the answer above, Windows API is accessed via the windows.h header file included.

Russellrusset answered 2/12, 2012 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.