-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanageFile.c
More file actions
136 lines (117 loc) · 2.64 KB
/
manageFile.c
File metadata and controls
136 lines (117 loc) · 2.64 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
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
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <iostream>
#include <fcntl.h>
void createFolder() {
printf("Input folder name need to create: ");
char *nameOfFolder = new char[50];
scanf("%s", nameOfFolder);
int check = mkdir(nameOfFolder, 0777);
if(check == -1)
printf("Error with create new folder \n" );
else
printf("Success with create new folder \n" );
}
void createFile() {
printf("Please input name of file: ");
char *filename = new char[50];
scanf("%s", filename);
int fd2 = open(filename,0777);
if (fd2 != -1) {
close(fd2);
}
printf("Create file successfull! \n");
delete filename;
}
void deleteFile() {
printf("Input file name need to delete: ");
char *nameOfFile = new char[50];
scanf("%s", nameOfFile);
if( remove( nameOfFile ) != 0 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );
}
void appendFile() {
FILE *pFile;
printf("Input file name need to append: ");
char *nameOfFile = new char[50];
getchar();
scanf("%99[^\n]", nameOfFile);
printf("Input content need to append: ");
getchar();
char *content = new char[50];
scanf("%99[^\n]", content);
pFile=fopen(nameOfFile, "a");
fprintf(pFile, "\n");
fprintf(pFile, content);
fclose(pFile);
}
int main()
{
char check = '1';
char choice;
while(check == '1'){
printf("a.Create new folder \n");
printf("b.Create new file \n");
printf("c.Delete file \n");
printf("d.Append file \n");
printf("Please choice (a/b/c/d) \n");
scanf("%s",&choice);
switch(choice){
case 'a':
createFolder();
printf("1.Continue \n");
printf("2.Quit \n");
printf("Please choice(1/2) \n");
char choice2;
scanf("%s",&choice2);
if(choice2 == '2')
check = '0';
else
check = '1';
break;
case 'b':
createFile();
printf("1.Continue \n");
printf("2.Quit \n");
printf("Please choice(1/2) \n");
char choice3;
scanf("%s",&choice3);
if(choice3 == '2')
check = '0';
else
check = '1';
break;
case 'c':
deleteFile();
printf("1.Continue \n");
printf("2.Quit \n");
printf("Please choice(1/2) \n");
char choice4;
scanf("%s",&choice4);
if(choice4 == '2')
check = '0';
else
check = '1';
break;
case 'd':
appendFile();
printf("1.Continue \n");
printf("2.Quit \n");
printf("Please choice(1/2) \n");
char choice5;
scanf("%s",&choice5);
if(choice5 == '2')
check = '0';
else
check = '1';
break;
}
system("clear");
}
}