Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 479
Rakesh Malik Avatar asked May 02 '14 12:05

Rakesh Malik


People also ask

How to include dirent h in Visual Studio?

To make Dirent available to all C/C++ projects in your machine, simply copy include/dirent. h file to the system include directory, e.g. C:\Program Files\Microsoft Visual Studio 9.0\VC\include . Everything you need is included in the single dirent.

What is struct dirent in c++?

A dirent structure contains the character pointer d_name, which points to a string that gives the name of a file in the directory. This string ends in a terminating NULL, and has a maximum of NAME_MAX characters. Save the data from readdir(), if required, before calling closedir(), because closedir() frees the data.


1 Answers

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
}
like image 63
Rakesh Malik Avatar answered Sep 30 '22 06:09

Rakesh Malik