35657

Untitled

Jul 24th, 2023
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <filesystem>
  7. #include <windows.h>
  8.  
  9.  
  10. using namespace std;
  11.  
  12. using filesystem::path;
  13.  
  14.  
  15. // вывод содержимого директории с указанием размера для файлов
  16. void PrintDirectoryInfo(const string& str) { // указываем путь к папке
  17.     for (const auto& a : filesystem::directory_iterator(str)) { // обход всех файлов в директории
  18.         string name = a.path().filename().string();
  19.         string full_name = str + '/' + name;
  20.         cout << setw(30) << name;
  21.         if (filesystem::is_regular_file(full_name)) {
  22.             cout << " " << setw(10) << filesystem::file_size(full_name) << " byte";
  23.         }
  24.         cout << endl;
  25.     }
  26. }
  27.  
  28.  
  29. int main() {
  30.  
  31.     SetConsoleCP(1251); // установка кодировки 1251 в поток ввода
  32.     SetConsoleOutputCP(1251); // установка кодировки 1251 в поток вывода
  33.  
  34.     PrintDirectoryInfo("C:/Users/PC/Desktop");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment