Created
August 7, 2016 21:15
-
-
Save bortkiewicz/8de1e8c6aa38c5c6c5da7a26800af252 to your computer and use it in GitHub Desktop.
see the disk usage
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
import os | |
import os.path | |
import sys | |
sys.setrecursionlimit(2147483647) | |
def disk_usage(path, ind=0): | |
total = os.path.getsize(path) | |
if os.path.isdir(path): | |
for filename in os.listdir(path): | |
childpath = os.path.join(path, filename) | |
try: | |
i = disk_usage(childpath, ind+1) | |
print(" "*ind + "%s is %s bytes" % (childpath, i)) | |
total += i | |
except PermissionError: | |
print(" "*ind + "Permission was denied to %s. Assuming it was 0 bytes." % childpath) | |
return total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment