Created
May 24, 2017 14:00
-
-
Save 223n/467ce5f2aa19c7a954b10b61be1c2f65 to your computer and use it in GitHub Desktop.
C++で指定したフォルダのサイズを求めようとしていた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <string> | |
#include <filesystem> | |
using namespace std; | |
using namespace std::tr2::sys; | |
void getFoldersize(string rootFolder,unsigned long long & f_size) | |
{ | |
path folderPath(rootFolder); | |
if (exists(folderPath)) | |
{ | |
directory_iterator end_itr; | |
for (directory_iterator dirIte(rootFolder); dirIte != end_itr; ++dirIte ) | |
{ | |
path filePath(complete (dirIte->path(), folderPath)); | |
try { | |
if (!is_directory(dirIte->status()) ) | |
{ | |
f_size = f_size + file_size(filePath); | |
}else | |
{ | |
getFoldersize(filePath,f_size); | |
} | |
} | |
catch(exception& e){ cout << e.what() << endl; } | |
} | |
} | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
unsigned long long f_size = 0; | |
getFoldersize("C:\\", f_size); | |
cout << f_size << endl; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment