title: How do I recursively change permissions using c++ or boost so I can get directory size
body: <p>I have the following code so that I can get the size of a directory on my system</p>
  
  <pre><code>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 &lt;&lt; "Size of Directory: " &lt;&lt; size &lt;&lt; endl;
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>permissions(file_path, add_perms|owner_write|group_write|others_write);
  </code></pre>
  
  <p>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. </p>
  
  <p>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. </p>