Can't find mkdir() function in dirent.h for windows

Rakesh Malik picture Rakesh Malik · May 2, 2014 · Viewed 23k times · Source

I am using dirent.h 1.20 (source) for windows in VC2013.

I can't find mkdir() in it.

How am I supposed to use it? Or can I create a directory somehow only using dirent.h?

Answer

Rakesh Malik picture Rakesh Malik · May 3, 2014

simplest way that helped without using any other library is.

#if defined _MSC_VER
#include <direct.h>
#elif defined __GNUC__
#include <sys/types.h>
#include <sys/stat.h>
#endif

void createDir(string dir) {
#if defined _MSC_VER
    _mkdir(dir.data());
#elif defined __GNUC__
    mkdir(dir.data(), 0777);
#endif
}