Problem: Write a C/C++ program to create a folder in a specific directory path.
This task can be accomplished by using the mkdir() function. Directories are created with this function. (There is also a shell command mkdir which does the same thing). The mkdir() function creates a new, empty directory with name filename.
// mkdir() function int mkdir (char *filename)
Note: A return value of 0 indicates successful completion, and -1 indicates failure.
- Program to create a directory in Windows using Turbo C compiler:
// C program to create a folder
* dirname =
check = mkdir(dirname,0777);
// check if directory is created or not
"Unable to create directory\n"
Directory created. a.out geeskforgeeks main.c
- Program to create a directory in Linux/Unix using GCC/G++ compiler:
// C++ program to create a directory in Linux
// Creating a directory
, 0777) == -1)
"Error : "
) << endl;
Note: Above source codes would not run on online IDEs as the program requires the directory path in the system itself.
This article is contributed by Rishav Raj. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Create a shared Folder between Host OS and Guest OS ( Virtual Box)
- How to create a Shared Folder between two Local User in Linux?
- mindepth and maxdepth in Linux find() command for limiting search to a specific directory.
- Implementing Directory Management using Shell Script
- How to check if a directory or a file exists in system or not using Shell Scripting?
- Automated Recursive Encryption in a Directory Using Shell Script
- C++ program to create a file
- Program to create Custom Vector Class in C++
- C Program to create a House using Graphics
- C program to create copy of a singly Linked List using Recursion
- Create n-child process from same parent process using fork() in C
- Create a Virtual Machine and Set up API on Google Cloud
- Create a password generator using shell scripting
- How to create a Class in JShell of Java 9
- How to create a Heart using C Graphics
- Create your own secure Home Network using Pi-hole and Docker
- Using mkvirtualenv to create new Virtual Environment - Python
- How to create a custom String class in C++ with basic functionalities
- How to Create Reverse Shells with Netcat in Kali Linux?
- How to create a command-line progress bar in C/C++
Improved By : santoshbommanalli