35657

Untitled

Jul 15th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <windows.h>
  6. #include <filesystem>
  7.  
  8. using namespace std;
  9.  
  10. void PrintDirectory(const string& str) { // вывод содержимого директории
  11.     for (const auto& a : filesystem::directory_iterator(str)) {
  12.         cout << a.path().filename().string() << endl;
  13.     }
  14. }
  15.  
  16.  
  17. void PrintDirectoryInfo(const string& str) { // вывод содержимого директории c с указанием размера вложенных файлов
  18.     for (const auto& a : filesystem::directory_iterator(str)) {
  19.         string name = a.path().filename().string();
  20.         string full_name = str + '/' + name;
  21.         cout << setw(30) << name;
  22.         if (filesystem::is_regular_file(full_name)) {
  23.             cout << " " << setw(10) << filesystem::file_size(full_name) << " byte";
  24.         }
  25.         cout << endl;
  26.     }
  27. }
  28.  
  29. int main()
  30. {
  31.  
  32.     SetConsoleCP(1251);
  33.     SetConsoleOutputCP(1251);
  34.  
  35.     /*filesystem::create_directory("C:/Users/PC/Desktop/temp");
  36.     filesystem::create_directories("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5");
  37.  
  38.  
  39.     ofstream fout("C:/Users/PC/Desktop/temp/file.txt");
  40.     ofstream fout2("C:/Users/PC/Desktop/temp/temp2/file2.txt");
  41.     ofstream fout3("C:/Users/PC/Desktop/temp/temp2/1/file3.txt");
  42.     ofstream fout4("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt");*/
  43.     //fout4.close();
  44.     //filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5"); // удаление пустой папки (не забываем закрыть вложенные файлы)
  45.     //filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt"); // не забываем закрывать файл
  46.     //filesystem::remove_all("C:/Users/PC/Desktop/temp"); // удаление папки с содержимым (не забываем закрыть вложенные файлы)
  47.     //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Desktop/temp33"); // переименование файлов и каталогов
  48.     //filesystem::rename("C:/Users/PC/Desktop/temp33", "C:/temp33"); // перенос файлов и каталогов
  49.     //filesystem::rename("C:/temp33", "C:/Users/PC/Desktop/temp2"); // перенос и переименование файлов и каталогов
  50.     //filesystem::copy("C:/Users/PC/Desktop/temp33/temp2/1/2/3/4/5", "C:/Users/PC/Desktop/5"); // копирование файлов и каталогов с файлами но без вложенных каталогов
  51.     //filesystem::copy("C:/Users/PC/Desktop/temp33", "C:/Users/PC/Desktop/temp", filesystem::copy_options::recursive); // копирование папок с файлами и вложенными каталогами
  52.    /* cout << filesystem::file_size("C:/Users/PC/Desktop/temp/file.txt") << endl;
  53.     cout << boolalpha;
  54.     cout << filesystem::is_regular_file("C:/Users/PC/Desktop/temp/file.txt") << endl;
  55.     cout << filesystem::is_directory("C:/Users/PC/Desktop/temp/file.txt") << endl;
  56.     cout << filesystem::is_directory("C:/Users/PC/Desktop/temp") << endl;
  57.     cout << endl << endl;*/
  58.     PrintDirectoryInfo("C:/Users/PC/Desktop");
  59. }
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment