-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkdirFile.c
More file actions
79 lines (70 loc) · 1.92 KB
/
mkdirFile.c
File metadata and controls
79 lines (70 loc) · 1.92 KB
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
78
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include<stdlib.h>
#include<string.h>
// Tu shell.c file mein /name/ ke andar wale strings ko ek saath karke yahan bhej
// TU special charater /name/ ka use kar for above purpose
int main(int argc, char const *argv[])
{
//printf("Entered\n");
if ((argc == 2) && (strcmp(argv[1], "--help") == 0)) {
printf("Creates Directory\n");
printf("Options:\n");
printf("-v: It prints the name of the directories, after creating it.\n");
printf("--help: Prints information about this command\n");
exit(0);
}
else if ((argc >= 3) && (strcmp(argv[1], "-v") == 0)) {
for (int i = 2; i < argc; i++) {
int status = mkdir(argv[i], 0777);
if (status == -1) {
printf("Error: Directory %s can't be created\n", argv[i]);
}
else {
printf("mkdir: created Directory %s\n", argv[i]);
}
}
exit(0);
}
else if (argc >= 2 && (argv[1][0] == '"' && argv[argc - 1][strlen(argv[argc - 1]) - 1] == '"')) {
char myDir[400] = "";
//argv[argc - 1][strlen(argv[argc - 1]) - 1] = '\0';
//argv[1] = argv[1] + 1;
for (int j = 1; j < argc; j++) {
strcat(myDir, argv[j]);
if (j != argc - 1) {
strcat(myDir, " ");
}
}
//myDir = myDir + 1;
int len = strlen(myDir);
myDir[len-1] = '\0';
char* myDir1 = myDir;
myDir1 = myDir1 + 1;
mkdir(myDir1, 0777);
exit(0);
}
else if ((argc >= 2) && (strcmp(argv[1], "-v") != 0)) {
for (int i = 1; i < argc; i++) {
int status = mkdir(argv[i], 0777);
if (status == -1) {
printf("Error: Directory %s can't be created\n", argv[i]);
}
}
exit(0);
}
else {
printf("Error : There is an error in the arguments or options\n");
exit(1);
}
/*int status = mkdir("testDir1/testDir2", 0777); // Agar dirctory pehle se hi hain, toh bhi yeh bana deta hain. So, done
if (status == -1) {
printf("Error: Directory can't be created.");
exit(1);
}
else {
exit(0);
}*/
}