Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.