-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm.c
46 lines (45 loc) · 1.09 KB
/
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
45
46
//rm command
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
int main(int argc, char **args){
if(argc==3){
chdir("/");
chdir(*(args+2));
int x = remove(*(args+1));
if(x!=0){
printf("Unable to delete\n");
}
}
if(argc==4){
if(strcmp(*(args+1),"-v")==0){
chdir("/");
chdir(*(args+3));
printf("%s\n",*(args+2));
int x = remove(*(args+2));
if(x!=0){
printf("Unable to delete\n");
}
}
else if(strcmp(*(args+1),"-i")==0){
chdir("/");
chdir(*(args+3));
printf("remove %s?",*(args+2));
char choice;
scanf("%c",&choice);
if(choice=='Y'){
int x = remove(*(args+2));
if(x!=0){
printf("Unable to delete\n");
}
}
}
else{
printf("Invalid Command, argument required\n");
}
}
exit(0);
}