Advertisement
35657

Untitled

Apr 27th, 2024
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <Windows.h>
  5. #include <fstream>
  6. #include <filesystem>
  7.  
  8. using namespace std;
  9.  
  10. int directory_size(const string& str) {
  11.     int size = 0;
  12.     for (const auto& a : filesystem::directory_iterator(str)) {
  13.         string full_name = str + '/' + a.path().filename().string();
  14.         if (filesystem::is_regular_file(full_name)) {
  15.             size += filesystem::file_size(full_name);
  16.         }
  17.         if (filesystem::is_directory(full_name)) {
  18.             size += directory_size(full_name);
  19.         }
  20.     }
  21.     return size;
  22. }
  23.  
  24.  
  25. int main() {
  26.     SetConsoleCP(1251);
  27.     SetConsoleOutputCP(1251);
  28.  
  29.     cout << directory_size("C:/Users/PC/Desktop/Protobuf_windows") << endl;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement