Python tools for various use cases
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
437B

  1. import os
  2. from collections import defaultdict
  3. from pprint import pprint
  4. """
  5. Display the total file size of files in a directory and subdirectories,
  6. grouped by extension.
  7. """
  8. stats = defaultdict(int)
  9. for (dirpath, _, filenames) in os.walk(r"/put/some/path/here"):
  10. for filename in filenames:
  11. _, extension = os.path.splitext(filename)
  12. stats[extension] += os.path.getsize(os.path.join(dirpath, filename))
  13. pprint(stats)