Q:
C program to create a directory using system() function
belongs to collection: File Handling Examples Programs in C language
File Handling Examples Programs in C language
- C program to find number of lines in a file
- C program to create a text file using file handling, example of fopen, fclose
- C program to create, write and read text in/from file
- C program to print given number of lines of a file (like head command in Linux)
- C program to print contents in reverse order of a file (just like TAC command in Linux)
- C program to compare contents of two files
- C program to copy number of bytes from specific offset to another file
- C - Read Content of a File using getc() using C Program
- C - Convert All Characters in Upper Case of a File using C Program
- C program to delete a specified file using remove() function
- C program to delete a specified file using the system() function
- C program to remove a specified empty directory using the remove() function
- C program to remove an empty directory
- C program to remove a non-empty directory using the system() function
- C program to check a given filename is a directory or not
- C program to remove a specific line from the text file
- C program to replace the specified line in an existing text file
- C program to append the content of one file to the end of another file
- C program to print the list of files of a directory
- C program to print the list of files and subdirectories of the current directory
- C program to check a specified directory exists or not
- C program to check a specified file exists or not
- C program to check a specified file exists or not using the stat() function
- C program to check a specified file exists or not using the access() function
- C program to check a specified file has read, write, and execute permission or not
- C program to create a directory using mkdir() function
- C program to create a directory using system() function
- C program to remove an empty directory using rmdir() function
- C program to rename a file using the rename() function
- C program to rename a file using the system() function
- C program to change the permissions of file using system() function
- C program to capitalize the first letter of every word in a file
Input the name (path) of the directory, and then create the directory using the system() function.
The system() function is a library function of <stdlib.h> or <cstdlib> header file which is used to execute the commands that can be executed in the command processor or the terminal of the operating system, and finally returns the command after it has been completed.
Syntax:
The argument string is the command to be executed.
To create the directory at given path, we create the command and then pass it into system() function.
Program:
The source code to create a directory using system() function is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
Output:
Explanation:
Here, we created a character array dirName. Then we read the name of the directory from the user. Then we created the given directory using system() function and printed the appropriate message on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer