/
ConsoleApplication52.cpp
176 lines (165 loc) · 4.39 KB
/
ConsoleApplication52.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
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
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include "ComFile.h"
#include "ComDir.h"
using namespace std;
int main()
{
/*cout << "Name of first directory is <d1> " << endl << "in <d1> there are <d1_2> directory and files <f1> and <f2> and <f3>" << endl;
cout << "In <d1_2> file <f3>"<<endl<<endl;*/
ComDir d1("d1");
ComDir d2("d2");
/*ComDir d1_2("d1_2");
ComDir d1_3("d1_3");
ComDir d2_1("d2_1");*/
ComFile f1("f1", 1);
ComFile f2("f2", 2);
/*ComFile f3("f3", 3);
ComFile f4("f3", 4);
d1.addFile(f1);
f1.setData(2);
f1.reName("f1_2");
d1.addFile(f1);
d1.addFile(f2);
d1.addFile(f3);
d1_2.addFile(f3);
d1_2.addFile(f4);
d1_2.addDir(d2_1);
d1.addDir(d1_2);
d1.addDir(d1_3);
cout << "after using seatch <f3> in <d1> direcroty and lower programm found ";
d1.search(d1, "f3");
cout << "files" << endl;
cout << "after using seatch <f1> in <d1> direcroty and lower programm found ";
d1.search(d1, "f1");
cout << "files" << endl;
cout << "checking d1.getname and f1.getdata" << endl;
cout << d1.getName() << endl;
cout << f1.getData() << endl;
cout << endl << endl << endl;
d1.ListDir(d1);
cout << endl << endl;
d1.LSR(d1);
cout << endl << endl << endl << endl;
cout << endl << endl << endl;*/
string command = "start";
ComDir* Uptr = &d1;
ComDir* Stptr = &d1;
ComFile* Fileptr = &f1;
ComFile* NewFptr = &f2;
ComDir* NewDptr = &d2;
/*NewFptr = &f2;
NewDptr = &d2;
Uptr = &d1;
Stptr = &d1;
Fileptr = &f1;*/
cout << "Your first direktory is <d1>" << endl;
cout << "to come to d1 use command gotop" << endl;
cout << "These are coomands to use" << endl << "list - to see what is in the directory" << endl << "ListALL - to see what is lower the directory" << endl << "cd - to go through direktories";
cout << endl << "open - to use file" << endl << "write - to chande data on an opened file" << endl << "search - to see in what directories(that are lower or actually the using one) there are files with a needed name" << endl;
cout << "newfile - to create new file in the current directory" << endl << "newdir - to create new dir in the curreant directory" << endl << "dname - to change current dir name" << endl << "fname - to change current file name" << endl; ;
cout << "getdata - data of opened file" << endl<< "delfile - to delete file from current directory"<< endl;
while (command != "end")
{
try {
cin >> command;
if (command == "delfile")
{
cout << "enter name of file"<<endl<<endl;
string name;
cin >> name;
Uptr->delFile(name);
}
if (command == "getdata")
{
cout << Fileptr->getData() << endl << endl;
}
if (command == "dname")
{
cout << "enter name" << endl << endl;
string name;
cin >> name;
Uptr->setName(name);
}
if (command == "fame")
{
cout << "enter name" << endl << endl;
string name;
cin >> name;
Fileptr->reName(name);
}
if (command == "gotop")
{
Uptr = Stptr;
cout << "we now at the top directory" << endl << endl;
}
if (command == "newfile")
{
int data;
string name;
cout << "Enter name and data" << endl << endl;
cin >> name >> data;
NewFptr->reName(name);
NewFptr->setData(data);
Uptr->addFile(*NewFptr);
cout << "New File was created" << endl << endl;
}
if (command == "newdir")
{
string name;
cout << "Enter name" << endl << endl;
cin >> name;
NewDptr->setName(name);
Uptr->addDir(*NewDptr);
cout << "New Directory were created" << endl << endl;
}
if (command == "ListALL")
{
Uptr->LSR(*Uptr);
}
if (command == "list")
{
Uptr->ListAll();
}
if (command == "cd")
{
cout << "enter name of directory" << endl << endl;
ComDir* Tempptr = new ComDir;
Tempptr = (Uptr->cd());
Uptr = Tempptr;
}
if (command == "open")
{
cout << "enter name of file" << endl << endl;
Fileptr = Uptr->open();
}
if (command == "write")
{
cout << endl << "cin int " << endl << endl;
int k;
cin >> k;
Fileptr->setData(k);
}
if (command == "search")
{
string name;
cout << "cin name of file" << endl << endl;
cin >> name;
Uptr->search(*Uptr, name);
}
/*else
{
cout << endl << "wrong command" << endl;
}*/
}
catch (invalid_argument& e)
{
cerr << e.what() << endl;
//return -1;
}
}
system("pause");
return 0;
}