-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkdir.c
77 lines (69 loc) · 1.49 KB
/
mkdir.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
// 1 -v
// 2 -p
// 3 normal
int main(int argc,char* argv[]){
char input2[100];
strcpy(input2,argv[0]);
char *t=strtok(argv[0]," ");//mkdir
t=strtok(NULL," "); //option
if(!strcmp(t,"-v")){
int c;
t=strtok(NULL," ");
while(t!=NULL){
c=mkdir(t,0777);
if(c==-1){
printf("%s directory not created\n",t);
}
else{
printf("%s directory created\n",t);
}
t=strtok(NULL," ");
}
}
else if(!strcmp(t,"-p")){
int c;
t=strtok(NULL," ");
char *dir=strtok(input2," "); //mkdir
dir =strtok(NULL," "); //-p
dir=strtok(NULL,"/");
c=mkdir(dir,0777);
if(c==-1){
printf("%s Directory not created\n",dir);
}else{
printf("%s Directory created\n",dir);
}
c=mkdir(t,0777);
if(c==-1){
printf("%s Directory not created\n",t);
}else{
printf("%s Directory created\n",t);
}
}
else if(t[0]=='-'){
printf("Either the command does not exist or is not handeled in mkdir");
}
else if(t==NULL){
printf("You need to provide a directory name");
}
else{
// t=strtok(NULL," ");
// printf("%s heloo\n",t);
int c=mkdir(t,0777);
if(c==-1){
printf("%s directory not created\n",t);
}
else{
printf("%s directory created\n",t);
}
}
}