Q:
C program to remove a non-empty directory using the 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
In this program, we will read the name of the non-empty directory, and then we will remove the given non-empty directory using the system() function by specifying the "rm" command.
Program:
The source code to remove a non-empty directory 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 removed the non-empty directory using the system() function. The system() function is used to execute the command. So, we created a command using the sprintf() function. Then we pass the created command in the system() function and removed the given non-empty directory. After that, we printed the appropriate message on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer