Untitled
unknown
plain_text
2 years ago
2.7 kB
9
Indexable
#include <iostream>
#include <string>
#include <locale.h>
using namespace std;
string file_format(const string file) {
string format;
int i = file.size() - 1;
char current = file[i];
while (current != '.') {
format += current;
i--;
current = file[i];
}
reverse(format.begin(), format.end());
return format;
}
string file_name(const string file) {
string name;
int i = file.size() - 1;
char current = file[i];
while (i > 0) {
if (current == '.') {
i--;
current = file[i];
while (current != '\\') {
name += current;
i--;
current = file[i];
}
}
else {
i--;
current = file[i];
}
}
reverse(name.begin(), name.end());
return name;
}
string file_path(const string file) {
string path;
for (int i = 0; i < (file.size() - file_format(file).size() - file_name(file).size() - 2); i++) {
path += file[i];
}
return path;
}
string file_disk(const string file) {
string disk;
int i = 0;
char current = file[i];
while (current != '\\') {
disk += file[i];
i++;
current = file[i];
}
return disk;
}
int main() {
setlocale(LC_ALL, "Russian");
int choice;
bool stop = false;
string fpath;
while (not stop) {
cout << "Выберите действие:" << endl << "1. Расширение." << endl << "2. Название." << endl << "3. Расположение." << endl << "4. Диск" << endl << "5. Переименование." << endl << "6. Копия файла." << endl << "7. Выход." << endl;
cin >> choice;
switch (choice) {
case 1:
fpath.clear();
cout << "Введите путь к файлу: ";
cin >> fpath;
cout << "Расширение: ." << file_format(fpath) << endl;
break;
case 2:
fpath.clear();
cout << "Введите путь к файлу: ";
cin >> fpath;
cout << "Название: " << file_name(fpath) << endl;
break;
case 3:
fpath.clear();
cout << "Введите путь к файлу: ";
cin >> fpath;
cout << "Расположение: " << file_path(fpath) << endl;
break;
case 4:
fpath.clear();
cout << "Введите путь к файлу: ";
cin >> fpath;
cout << "Диск: " << file_disk(fpath) << endl;
break;
case 5:
fpath.clear();
cout << "Введите путь к файлу: ";
cin >> fpath;
break;
case 6:
fpath.clear();
cout << "Введите путь к файлу: ";
cin >> fpath;
break;
case 7:
stop = true;
break;
default:
cout << "Введено неверное значение.";
break;
}
}
}Editor is loading...