-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.cpp
More file actions
52 lines (43 loc) · 1.16 KB
/
Copy pathFileManager.cpp
File metadata and controls
52 lines (43 loc) · 1.16 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
#include <iostream>
#include <cstdlib> // For system()
#include <fstream>
#include <string>
using namespace std;
void listFiles(const string& path) {
string command = "dir " + path; // For Windows
system(command.c_str()); // Executes the command in the terminal
}
void viewFile(const string& path) {
ifstream file(path.c_str());
if (!file) {
cout << "Error: Cannot open file.\n";
return;
}
string line;
while (getline(file, line)) {
cout << line << "\n";
}
file.close();
}
int main() {
string command, arg;
cout << "Simple File Manager\n";
cout << "Commands: list <path>, view <file>, exit\n";
while (true) {
cout << "> ";
cin >> command;
if (command == "list") {
cin >> arg;
listFiles(arg);
} else if (command == "view") {
cin >> arg;
viewFile(arg);
} else if (command == "exit") {
cout << "Exiting File Manager. Goodbye!\n";
break;
} else {
cerr << "Unknown command. Try again.\n";
}
}
return 0;
}