Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <windows.h>
- #include <filesystem>
- using namespace std;
- void PrintDirectory(const string& str) { // вывод содержимого директории
- for (const auto& a : filesystem::directory_iterator(str)) {
- cout << a.path().filename().string() << endl;
- }
- }
- void PrintDirectoryInfo(const string& str) { // вывод содержимого директории c с указанием размера вложенных файлов
- 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(full_name)) {
- cout << " " << setw(10) << filesystem::file_size(full_name) << " byte";
- }
- cout << endl;
- }
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- /*filesystem::create_directory("C:/Users/PC/Desktop/temp");
- filesystem::create_directories("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5");
- ofstream fout("C:/Users/PC/Desktop/temp/file.txt");
- ofstream fout2("C:/Users/PC/Desktop/temp/temp2/file2.txt");
- ofstream fout3("C:/Users/PC/Desktop/temp/temp2/1/file3.txt");
- ofstream fout4("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt");*/
- //fout4.close();
- //filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5"); // удаление пустой папки (не забываем закрыть вложенные файлы)
- //filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt"); // не забываем закрывать файл
- //filesystem::remove_all("C:/Users/PC/Desktop/temp"); // удаление папки с содержимым (не забываем закрыть вложенные файлы)
- //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Desktop/temp33"); // переименование файлов и каталогов
- //filesystem::rename("C:/Users/PC/Desktop/temp33", "C:/temp33"); // перенос файлов и каталогов
- //filesystem::rename("C:/temp33", "C:/Users/PC/Desktop/temp2"); // перенос и переименование файлов и каталогов
- //filesystem::copy("C:/Users/PC/Desktop/temp33/temp2/1/2/3/4/5", "C:/Users/PC/Desktop/5"); // копирование файлов и каталогов с файлами но без вложенных каталогов
- //filesystem::copy("C:/Users/PC/Desktop/temp33", "C:/Users/PC/Desktop/temp", filesystem::copy_options::recursive); // копирование папок с файлами и вложенными каталогами
- /* cout << filesystem::file_size("C:/Users/PC/Desktop/temp/file.txt") << endl;
- cout << boolalpha;
- cout << filesystem::is_regular_file("C:/Users/PC/Desktop/temp/file.txt") << endl;
- cout << filesystem::is_directory("C:/Users/PC/Desktop/temp/file.txt") << endl;
- cout << filesystem::is_directory("C:/Users/PC/Desktop/temp") << endl;
- cout << endl << endl;*/
- PrintDirectoryInfo("C:/Users/PC/Desktop");
- }
Advertisement
Add Comment
Please, Sign In to add comment