Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++, List all files, dirent.h on Windows

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.

like image 641
blubberbernd Avatar asked Apr 30 '11 08:04

blubberbernd


People also ask

Does dirent H work for Windows?

dirent. h is a header file that is found only on Linux systems. It provides data structures and function calls to open and read the contents of directories. If you are trying to port Linux code that uses this header file to Windows, you will that it is not available with Visual Studio.

What is #include dirent H?

Description. The /usr/include/dirent. h file describes the format of a directory entry without reference to the type of underlying system. The dirent structure, defined in the dirent. h file, is used for directory access operations.

What is dirent H header file?

The dirent. h header file contains constants, prototypes, and typedef definitions for POSIX directory access functions.


2 Answers

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

like image 182
Ignacio Vazquez-Abrams Avatar answered Sep 30 '22 00:09

Ignacio Vazquez-Abrams


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

like image 44
jonsca Avatar answered Sep 29 '22 23:09

jonsca