35657

Untitled

Aug 24th, 2024
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 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. using namespace std;
  10.  
  11. int get_directory_size(const string& str) {
  12.     int size = 0;
  13.     for (const auto& a : filesystem::directory_iterator(str)) {
  14.         string full_name = str + '/' + a.path().filename().string();
  15.         if (filesystem::is_regular_file(full_name)) {
  16.             size += filesystem::file_size(full_name);
  17.         }
  18.         if (filesystem::is_directory(full_name)) {
  19.             size += get_directory_size(full_name);
  20.         }
  21.     }
  22.     return size;
  23. }
  24.  
  25.  
  26.  
  27. int main() {
  28.  
  29.     SetConsoleCP(1251); // установка кодировки 1251 в поток ввода
  30.     SetConsoleOutputCP(1251); // установка кодировки 1251 в поток вывода
  31.  
  32.     cout << get_directory_size("C:/Users/PC/Desktop/Protobuf_windows") << " bytes";
  33.  
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment