-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileOperations.cpp
64 lines (62 loc) · 1.26 KB
/
FileOperations.cpp
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
#include"headers.h"
void CreateFolder()
{
char c;
gotoxy(tot_file+1,1);
string t;
string temp=dir_ent[curr_x-1];
temp=root;
cout<<"do you want to create a directory[y/n]\n";
cin>>c;
if(c=='y')
{
cout<<"enter the name of the directory to be created\n";
cin>>t;
t=temp.substr(0,temp.find_last_of("//"))+"/"+t;
if(mkdir(t.c_str(),0777)==-1)
{
cerr<<"error : "<<strerror(errno)<<endl;
}
else
{
ExploreDirectory(temp.substr(0,temp.find_last_of("//")).c_str());
curr_x=1;
gotoxy(curr_x,1);
getchar();
}
}
else
{
ExploreDirectory(temp.substr(0,temp.find_last_of("//")).c_str());
curr_x=1;
gotoxy(curr_x,1);
}
}
void CreateFile()
{
gotoxy(tot_file+1,1);
string temp;
temp=root;
char c;
string fname;
cout<<"do you want to create a file[y/n]\n";
cin>>c;
if(c=='y')
{
cout<<"enter the file name to be created(with extension) : ";
cin>>fname;
fname=temp.substr(0,temp.find_last_of("//"))+"/"+fname;
std::ofstream file { fname };
cout<<"file created successfully\n";
ExploreDirectory(temp.substr(0,temp.find_last_of("//")).c_str());
curr_x=1;
gotoxy(curr_x,1);
getchar();
}
else
{
ExploreDirectory(temp.substr(0,temp.find_last_of("//")).c_str());
curr_x=1;
gotoxy(curr_x,1);
}
}