Dirent is an application programming interface (API) that enables programmers to list files and directories. Dirent is commonly available in UNIX systems but only a few compilers in Windows provide an equivalent interface. In particular, the popular Microsoft Visual Studio package lacks a dirent interface.
Hence, if you are porting software to Windows, you may find yourself rewriting code for Microsoft specific APIs. In order to reduce this work, I have create a clone of the dirent interface for Microsoft Visual Studio. The interface attempts to mimic the genuine UNIX API so that you could use the familiar UNIX data structures and function calls in both Windows and UNIX without modifying your source code for one platform or the other.
At first, download dirent installation package from softagalleria.net. The latest version is 1.11.
To install dirent, unpack the zip file and copy the
dirent.h file to system include directory. The system
include directory contains header files such as assert.h
and windows.h, and it is usually located at
C:\Program Files\Microsoft Visual Studio 8\VC\include.
Dirent API is implemented completely in the dirent.h file and you can use dirent just as in UNIX once you copy the file. However, please note that dirent.h defines WIN32_LEAN_AND_MEAN macro and it includes windows.h header. This means that:
For more information on using dirent, please see Wikipedia and Open Group. The installation package also contains an example program with Visual Studio 2005 project file.
I created the dirent port for Windows in 1998 when only a few alternatives were available. However, the situation has changed since then and nowadays both Cygwin and MingW compilers allow you to compile a great number of UNIX programs in Windows. Both compilers even provide a full dirent API for Windows as well as many other UNIX APIs. MingW can even be used for commercial applications.