35657

Untitled

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