-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
214 lines (113 loc) · 3.41 KB
/
main.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*PROJECT IS TO DISCOVER THE DIRECTORY THROUGH THE STANDARD LIBRARY dir.h.
GUIDED BY:-SACHIDANAND SWAMI.*/
#include <errno.h>
#include <dirent.h>// <dirent.h> declares the following functions for opening, reading, and closing,a directory etc.
#include <stdio.h>
#include <stdlib.h>
int main()
{
DIR *rohit;
struct dirent *changani;
char c[100];
char s[100];
int p;
char *k;
int a;
int i;
strcpy(c,"");
doagain:
doagain1:
printf("\n");
printf("To read a directory press 1 : \n");
printf("To create a directory press 2 : \n");
printf("To erase a directory press 3 : \n");
printf("To exit the program press 4 : \n");
printf("To refresh press 5 : \n");
printf("To move back press 6 : \n");
printf("To view current directory 7 : \n");
printf("Before erasing the directory,please refresh the program by pressing 5,Then \nchoose the erase option.\n");
scanf("%d",&a);
fflush(stdin);
if(a==7)//To view the current directory.
{
puts(c);
}
if(a==6)//To rewind back to the directory.
{
for(k=c;*k!='\0';k++);
while(*k!='\\')//compiler do not get single backslash.
{
k--;
}
*k='\0';
puts(c);
goto doagain1;
}
if(a==5)//Refresh the program to clear the string being appended step by step.
{
puts(c);
c[0]='\0';
puts(c);
goto doagain1;
}
if(a==4)//To exit through the program.
{
exit(1);
}
printf("Enter a directory : ");//Asking fro path name for which the action is to be performed.
gets(s);
fflush(stdin);
i=strlen(c);
puts(c);
if(i==0)
{
strcpy(c,s);//Copies entered pathname to string.
}
else
{
strcat(c,s);//Appending the further direction given by user.
}
if(a==1)//Opening of directory.
{
rohit=opendir(c); /*To open a directory, we used opendir().
This function returns a pointer to a DIR data structure that represents a directory.*/
if (!rohit)// A NULL value indicates an error. pathname must be a name of an existing directory.
{
printf ("Sorry,the directory does not exist.\n");
}
errno=0;
while ((changani=readdir(rohit)))//After opening a directory, we used readdir() to traverse it.
{
printf("%s\n", changani->d_name);
}
if (errno)
{
printf ("Sorry,the directory cant be read.\n");
}
closedir(rohit);//After viewing the contents of directory we need to close it explicitly by calling closedir().
printf("\n\n\n");
}
if(a==2)
{
mkdir(c);/*To create a new directory, we use mkdir().
"c" is the name of the directory to be created.
If it's an existing file name or an invalid directory string, mkdir() fails.*/
printf("Directory created \n");
}
if(a==3)
{
rmdir(c);/*To delete an existing directory, use rmdir().
The directory must be empty. Otherwise, rmdir() fails.*/
printf("Directory erased \n");
}
goto doagain;
system("PAUSE");
return 0;
}
/*
MADE BY:-
ROHIT KUMAR SINGH ANIRUDH CHHANGNI
B.TECH FY CSE B.TECH FY CSE
2011-12 2011-12
8107740393 9530450508
*/