Skip to content

Instantly share code, notes, and snippets.

@223n

223n/code.cpp

Created May 24, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.