Cannot find mkdir () function in dirent.h for windows

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

I can not find mkdir()in it.

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

+4
source share
5 answers

The header you refer to effectively turns your (POSIX) dirent.hcalls into (native) Windows calls. But dirent.h- this is _dir_ectory _ent_ries, that is, reading directories, not creating.

If you want to create a directory ( mkdir()), you will need:

  • (POSIX) mkdir() () Windows ( )
  • Windows API, , POSIX Windows...

// UGLY - these two don't belong in the same source...
#include <dirent.h>
#include <windows.h>

// ...
CreateDirectory( "D:\\TestDir", NULL );
// ...

Cygwin, POSIX, Windows, Bash shell, GCC POSIX, dirent.h, sys/stat.h, sys/types.h .., POSIX API .

+2

, - , -

#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
}
+10

Visual Studio <direct.h>. _ mkdir _wmkdir, C, Visual Studio.

"" Windows API, DevSolar.

+1

sys/types.h mkdir(const char*)

#include<stdio.h>
#include<string.h>
#include <unistd.h>
#include<sys/stat.h>
#include<sys/types.h>
int main()
{
    if(!mkdir("C:mydir"))
    {
        printf("File created\n");
    }
    else
        printf("Error\n");
}
0

Mkdir . #include <direct.h> .

_mkdir("C:/folder")
0

Source: https://habr.com/ru/post/1538996/


All Articles