title: Disk usage of a directory in Python
body: <p>I have some bash code which <a href="https://github.com/adamatan/rmf" rel="nofollow">moves files and directory to <code>/tmp/rmf</code> rather than deleting them</a>, for safety purposes.</p>
  
  <p>I am migrating the code to Python to add some functionality. One of the added features is checking the available size on <code>/tmp</code> and asserting that the moved directory can fit in <code>/tmp</code>.</p>
  
  <p>Checking for available space is done using <a href="http://docs.python.org/2/library/os.html#os.statvfs" rel="nofollow">os.statvfs</a>, but how can I measure the disk usage of the moved directory?</p>
  
  <p>I could either call <code>du</code> using <code>subprocess</code>, or recursively iterate over the directory tree and sum the sizes of each file. Which approach would be better?</p>