Created
June 20, 2015 10:18
-
-
Save cgoldberg/61d237169a702234d548 to your computer and use it in GitHub Desktop.
walk a directory tree recursively. print total file count and size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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