-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final.c
140 lines (118 loc) · 2.77 KB
/
Final.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_SIZE 100
int main() {
int cmd = 1;
char command[MAX_SIZE];
char spec[MAX_SIZE];
char result[MAX_SIZE];
do {
printf("\n");
printf("1. Date\n");
printf("2. Current directory\n");
printf("3. Contents of current directory\n");
printf("4. Create file\n");
printf("5. Delete file\n");
printf("6. Read a text file\n");
printf("7. Write a text file\n");
printf("8. Create a folder\n");
printf("9. Delete a folder\n");
printf("10. Custom command\n");
printf("0. Exit\n");
printf("\n");
printf("Enter choice: ");
scanf("%d", &cmd);
printf("\n");
switch(cmd) {
case 1:
printf("Today's date is:\n");
system("date");
printf("\n");
break;
case 2:
system("pwd");
printf("\n");
break;
case 3:
system("ls");
break;
case 4:
printf("Enter file name:\n");
gets(spec);
fgets(spec,20,stdin);
char command4[MAX_SIZE] = "touch ";
strcat(command4, spec);
puts(command4);
system(command4);
printf("\n");
break;
case 5:
printf("Enter file name to be deleted:\n");
gets(spec);
fgets(spec,20,stdin);
char command5[MAX_SIZE] = "rm ";
strcat(command5, spec);
puts(command5);
system(command5);
printf("\n");
break;
case 6:
printf("Enter file name:\n");
gets(spec);
fgets(spec,20,stdin);
char command6[MAX_SIZE] = "cat ";
strcat(command6, spec);
puts(command6);
system(command6);
printf("\n");
break;
case 7:
printf("Enter file name:\n");
gets(spec);
fgets(spec,20,stdin);
char command7[MAX_SIZE] = "vi ";
strcat(command7, spec);
puts(command7);
system(command7);
printf("\n");
break;
case 8:
printf("Enter folder name:\n");
gets(spec);
fgets(spec,20,stdin);
char command8[MAX_SIZE] = "mkdir ";
strcat(command8, spec);
puts(command8);
system(command8);
printf("\n");
break;
case 9:
printf("Enter folder name:\n");
gets(spec);
fgets(spec,20,stdin);
char command9[MAX_SIZE] = "rmdir ";
strcat(command9, spec);
puts(command9);
system(command9);
printf("\n");
break;
case 10:
printf("\nCustom command:");
printf("\nEnter File or folder Name: ");
gets(spec);
fgets(spec,20,stdin);
printf("Enter command:\n");
gets(command);
strcat(command, spec);
puts(command);
system(command);
printf("\n");
break;
default:
break;
}
}
while(cmd != 0) ;
return 0;
}