C program to delete a file whose name (with extension) a user will input. The file must be present in the directory in which the executable of this program is present. Macro "remove" is used to delete the file. If there is an error in deleting the file, then it will be displayed by perror function.
C file deletion program
printf("Enter name of a file you wish to delete\n");
status = remove(file_name);
if (status == 0)
printf("%s file deleted successfully.\n", file_name);
printf("Unable to delete the file\n");
perror("Following error occurred");
Download Delete file program executable.
Output of program:
The deleted file doesn't go to the trash or recycle bin, so you may not be able to recover it. To recover deleted files special recovery software is required. The file recovery is possible if it isn't overwritten on the storage medium by other data.