I have the following code so that I can get the size of a directory on my system
size_t size = 0;
for(recursive_directory_iterator it("/Library/Caches");
it!=recursive_directory_iterator();
++it)
{
if(!is_directory(*it))
size+=file_size(*it);
}
cout << "Size of Directory: " << size << endl;
The problem with this is if boost encounters an error because of file permissions it throws and error. This has been a known bug with boost, from what I've read.
I thought if I could give my program read and write permissions for each item in the directory, that could fix this problem. So I found the following function in boost.
permissions(file_path, add_perms|owner_write|group_write|others_write);
I'm not 100% sure based on the current code above where to use this. I tried passing *it to the permissions function but that seems to throw an error as well.
wondering the best way to recursively change the permissions on a directory and files so that I can then use the recursive_directory_iterator without error in order to get the file size of all the items in a given directory.