Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <filesystem>
- #include <windows.h> // для работы SetConsoleCP, SetConsoleOutputCP
- using namespace std;
- using filesystem::path;
- void PrintDirectory(const string& str) {
- cout << "Содержимое папки " << str << ":" << endl;
- for (const auto& a : filesystem::directory_iterator(str)) {
- cout << a.path().filename().string() << endl;
- }
- }
- void PrintDirectoryInfo(const string& str) {
- cout << "Содержимое папки " << str << ":" << endl;
- for (const auto& a : filesystem::directory_iterator(str)) {
- string name = a.path().filename().string();
- string full_name = str + '/' + name;
- cout << setw(30) << name;
- if (filesystem::is_regular_file(path(full_name))) {
- cout << " " << setw(10) << filesystem::file_size(path(full_name)) << " byte";
- }
- cout << endl;
- }
- }
- int main() {
- SetConsoleCP(1251); // установка кодовой страницы windows cp 1251 в поток ввода
- SetConsoleOutputCP(1251); // установка кодовой страницы windows cp 1251 в поток вывода
- //filesystem::create_directory("C:/Users/PC/Desktop/temp"); // пустая папка
- //filesystem::create_directories("C:/Users/PC/Desktop/temp/1/2/3/4"); // папка с вложенными директориями
- //ofstream fout("C:/Users/PC/Desktop/temp/file.txt"); // создание файлов
- //ofstream fout2("C:/Users/PC/Desktop/temp/file2.txt");
- //ofstream fout3("C:/Users/PC/Desktop/temp/1/file3.txt");
- //ofstream fout4("C:/Users/PC/Desktop/temp/1/2/file4.txt");
- //fout.close();
- //fout2.close();
- //fout3.close();
- //fout4.close();
- //remove(path("C:/Users/PC/Desktop/temp/1/2/3/4")); // удаление пустой папки
- //remove_all(path("C:/Users/PC/Desktop/temp/1")); // удаление папки вместе с содержимым (обязательно закрыть файлы перед удалением)
- //copy(path("C:/Users/PC/Desktop/temp"), path("C:/Users/PC/Desktop/temp2")); // копирует папку с файлами на без вложенных каталогов
- //copy(path("C:/Users/PC/Desktop/temp"), path("C:/Users/PC/Desktop/temp2"), filesystem::copy_options::recursive); // копирует папку с файлами и вложенными каталогами
- //rename(path("C:/Users/PC/Desktop/temp2"), path("C:/Users/PC/Desktop/temp55")); // функция для переименования папок и файлов (в случае наличия вложенных файлов не забываем их закрыть)
- //rename(path("C:/Users/PC/Desktop/temp55"), path("C:/temp55")); // функция для перемещения папок и файлов (в случае наличия вложенных файлов не забываем их закрыть)
- //rename(path("C:/Users/PC/Desktop/temp55"), path("C:/Users/new_directory")); // функция для перемещения и переименования (в случае наличия вложенных файлов не забываем их закрыть)
- cout << boolalpha;
- cout << filesystem::is_regular_file(path("C:/Users/PC/Desktop/temp")) << endl; // проверить
- cout << filesystem::is_directory(path("C:/Users/PC/Desktop/temp")) << endl;
- cout << filesystem::file_size(path("C:/Users/PC/Desktop/temp/file.txt")) << " byte" << endl << endl << endl;
- PrintDirectory("C:/Users/PC/Downloads");
- cout << endl << endl;
- PrintDirectoryInfo("C:/Users/PC/Desktop/temp");
- }
Advertisement