Dirent API for Microsoft Visual Studio

Using Dirent API in Visual Studio
Dirent is now available also at GitHub


Dirent is an application programming interface (API) that enables programmers to list files and directories. Dirent API is commonly available in UNIX systems but not all compilers in Windows provide it. In particular, Microsoft Visual Studio lacks a dirent interface.

Thus, 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 source code for one platform or the other.

Download & Install

The latest version of dirent can be found at GitHub. Versions prior to 1.22 are archived at softagalleria.net.

To install dirent, unpack the zip file and copy includes/dirent.h file to system include directory. 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 9.0\VC\include. Dirent API is implemented completely in the dirent.h file and you can use dirent just as in UNIX once you haved copied the file.

The installation package also contains a few example programs and tests. You can compile the examples using CMake.

For more information on using dirent, please see Wikipedia and Open Group.

For Your Information

I created 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 provide a full dirent API for Windows as well as many other UNIX APIs, and MingW can even be used to create commercial applications.