-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIxFile.cpp
More file actions
144 lines (124 loc) · 6.17 KB
/
IxFile.cpp
File metadata and controls
144 lines (124 loc) · 6.17 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
137
138
139
140
141
142
143
144
#include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
using namespace std;
namespace fs = filesystem;
// Цвета ANSI
const string RED = "\033[31m";
const string GREEN = "\033[32m";
const string YELLOW = "\033[33m";
const string BLUE = "\033[34m";
const string MAGENTA = "\033[35m";
const string CYAN = "\033[36m";
const string RESET = "\033[0m";
const string BOLD = "\033[1m";
int main() {
int user;
fs::path current_path = fs::current_path();
cout << BOLD << CYAN << "📁 Простой файловый менеджер v1.0" << RESET << endl;
cout << YELLOW << "Проект распространяется по лицензии InterXlicense v1.0" << RESET << endl << endl;
while (true) {
cout << BOLD << MAGENTA << "Что вы хотите сделать? (введите цифру)" << RESET << endl;
cout << "1) " << BLUE << "Посмотреть путь до текущей директории" << RESET << endl;
cout << "2) " << BLUE << "Посмотреть содержимое текущей директории" << RESET << endl;
cout << "3) " << GREEN << "Прочитать файл" << RESET << endl;
cout << "4) " << YELLOW << "Создать файл" << RESET << endl;
cout << "5) " << RED << "Удалить файл" << RESET << endl;
cout << "6) " << CYAN << "Редактировать файл (дозапись)" << RESET << endl;
cout << "0) " << BOLD << RED << "Выйти из программы" << RESET << endl;
cout << YELLOW << "Введите число: " << RESET;
cin >> user;
if (user == 0) {
cout << GREEN << "👋 До свидания! Спасибо за использование!" << RESET << endl;
break;
}
cout << RESET << endl; // Отделение
if (user == 1) {
cout << BOLD << "Путь до текущей папки:" << RESET << " " << current_path << endl;
}
else if (user == 2) {
cout << BOLD << "Содержимое текущей директории:" << RESET << endl;
bool empty = true;
for (const auto& entry : fs::directory_iterator(current_path)) {
empty = false;
if (entry.is_directory()) {
cout << "[ " << BOLD << BLUE << "DIR" << RESET << " ] " << entry.path().filename() << endl;
} else {
cout << "[ " << GREEN << "FILE" << RESET << " ] " << entry.path().filename() << endl;
}
}
if (empty) {
cout << "📁 Папка пуста." << endl;
}
}
else if (user == 3) {
string filename;
cout << "Введите имя файла для чтения: ";
cin >> filename;
ifstream file(filename);
if (!file.is_open()) {
cout << RED << "❌ Ошибка: не удалось открыть файл '" << filename << "'" << RESET << endl;
} else {
cout << BOLD << "📄 Содержимое файла '" << filename << "':" << RESET << endl;
cout << "────────────────────────────────────" << endl;
string line;
while (getline(file, line)) {
cout << line << endl;
}
cout << "────────────────────────────────────" << endl;
file.close();
}
}
else if (user == 4) {
string filename;
cout << "Введите имя файла для создания: ";
cin >> filename;
ofstream file(filename);
if (file.is_open()) {
file.close();
cout << GREEN << "✅ Файл '" << filename << "' успешно создан!" << RESET << endl;
} else {
cout << RED << "❌ Ошибка: не удалось создать файл." << RESET << endl;
}
}
else if (user == 5) {
string filename;
cout << "Введите имя файла для удаления: ";
cin >> filename;
if (fs::exists(filename)) {
if (fs::remove(filename)) {
cout << RED << "🗑️ Файл '" << filename << "' успешно удалён." << RESET << endl;
} else {
cout << RED << "❌ Не удалось удалить файл." << RESET << endl;
}
} else {
cout << YELLOW << "⚠️ Файл '" << filename << "' не существует." << RESET << endl;
}
}
else if (user == 6) {
string filename;
cout << "Введите имя файла для редактирования: ";
cin >> filename;
ofstream file(filename, ios::app);
if (!file.is_open()) {
cout << RED << "❌ Ошибка: не удалось открыть файл '" << filename << "'" << RESET << endl;
} else {
cout << BOLD << CYAN << "✏️ Введите текст (введите 'SAVE' на новой строке, чтобы сохранить и выйти):" << RESET << endl;
string line;
cin.ignore(); // Игнорируем символ новой строки после cin
while (getline(cin, line)) {
if (line == "SAVE") break;
file << line << '\n';
}
file.close();
cout << GREEN << "💾 Файл '" << filename << "' успешно сохранён!" << RESET << endl;
}
}
else {
cout << RED << "⚠️ Неверный выбор. Пожалуйста, введите число от 0 до 6." << RESET << endl;
}
cout << "\n" << string(50, '-') << "\n" << endl; // Разделитель
}
return 0;
}