mkdir function not working in C

14,866

Solution 1

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;
}

Solution 2

Try this:

 #if defined(_WIN32)
    _mkdir("./newTempFolderName");
     #else 
    mkdir("./newTempFolderName", 0700); 
     #endif
Share:
14,866
Abhinav Kumar
Author by

Abhinav Kumar

Updated on June 08, 2022

Comments

  • Abhinav Kumar
    Abhinav Kumar about 2 years

    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;
    
              }