Create Directory or Folder with C/C++ Program
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:
* dirname = "geeksforgeeks";
check = mkdir(dirname,0777);
("Unable to create directory\n");
a.out geeksforgeeks main.c
- Program to create a directory in Linux/Unix using GCC/G++ compiler:
(mkdir("geeksforgeeks", 0777) == -1)
cerr << "Error : " <<
) << endl;
cout << "Directory created";
Note: Above source codes would not run on online IDEs as the program requires the directory path in the system itself. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!