Search code examples
cwindowsvisual-studio-2012mkdir

mkdir function not working in C


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;

          } 

Solution

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