Skip to content

Instantly share code, notes, and snippets.

@cgoldberg
Created June 20, 2015 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgoldberg/61d237169a702234d548 to your computer and use it in GitHub Desktop.
Save cgoldberg/61d237169a702234d548 to your computer and use it in GitHub Desktop.
walk a directory tree recursively. print total file count and size.
#!/usr/bin/env python
#
# walk a directory tree recursively.
# print total file count and size.
# Corey Goldberg, 2015
import os
start_dir = '/mnt/wd-green/Tunes'
file_count = 0
size_bytes = 0
for root, dirs, files in os.walk(start_dir):
for f in files:
file_count += 1
size_bytes += os.path.getsize(os.path.join(root, f))
size_mb = size_bytes / 1024 / 1024
print('found {} files, consuming {} MB of disk'.format(file_count, size_mb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment