-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrm.c
45 lines (42 loc) · 834 Bytes
/
rm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
int main(int argc,char *argv[]){
if(argc==2){
struct stat lol;
stat(argv[1],&lol);
if(S_ISDIR(lol.st_mode)){
printf("Error: Cannot delete Directory %s\n",argv[1] );
}
else{
remove(argv[1]);
}
}
if(argc==3){
if(strcmp(argv[1],"-i")==0){
struct stat lol;
stat(argv[2],&lol);
if(S_ISDIR(lol.st_mode)){
printf("Error: Cannot delete Directory %s\n",argv[2] );
}
else{
printf("Remove regular file %s?\n",argv[2] );
char option = getchar();
if(option=='y'){
remove(argv[2]);
}
}
}
else if(strcmp(argv[1],"-d")==0){
int alpha;
alpha = rmdir(argv[2]);
if(alpha==0){
printf("%s deleted \n",argv[2] );
}
else{
printf("Error: Directory not empty\n");
}
}
}
}