Skip to content

Instantly share code, notes, and snippets.

@223n
Created May 24, 2017 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 223n/467ce5f2aa19c7a954b10b61be1c2f65 to your computer and use it in GitHub Desktop.
Save 223n/467ce5f2aa19c7a954b10b61be1c2f65 to your computer and use it in GitHub Desktop.
C++で指定したフォルダのサイズを求めようとしていた
#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