Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mkdir function not working in C [duplicate]

I am trying to create a file in C by trying to execute the following code segment, but I am getting an "identifier "mkdir" is not defined". I am working on a Windows Machine using Visual Studio.

#include<stdio.h>

#include<sys/types.h>

#include<sys/stat.h>

    int main()

          {

   char newTempFolderName[50];

  int a = mkdir("./newTempFolderName", 0700);

    return 0;

          } 
like image 559
Abhinav Kumar Avatar asked Dec 05 '22 05:12

Abhinav Kumar


2 Answers

Use WinApi's CreateDirectory() function or use _mkdir() (notice the underscore sign).

Example of CreateDirectory() - you need to include windows.h header file:

#include<windows.h>

int main() {
   CreateDirectory ("C:\\test", NULL);
   return 0;
}
like image 161
macfij Avatar answered Dec 20 '22 14:12

macfij


Try this:

 #if defined(_WIN32)
    _mkdir("./newTempFolderName");
     #else 
    mkdir("./newTempFolderName", 0700); 
     #endif
like image 37
Marco Tulio Avatar answered Dec 20 '22 12:12

Marco Tulio