Created
June 6, 2011 18:17
-
-
Save tebeka/1010755 to your computer and use it in GitHub Desktop.
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 | |
| from os.path import getsize, isdir, exists, join | |
| from os import walk | |
| def main(argv=None): | |
| import sys | |
| from argparse import ArgumentParser | |
| argv = argv or sys.argv | |
| parser = ArgumentParser(description="Disk usage") | |
| parser.add_argument("root", help="root path") | |
| args = parser.parse_args(argv[1:]) | |
| if not exists(args.root): | |
| raise SystemExit("error: can't find %s" % args.root) | |
| if isdir(args.root): | |
| total = 0 | |
| for root, dirs, files in walk(args.root): | |
| for file in files: | |
| total += getsize(join(root, file)) | |
| else: | |
| total = getsize(args.root) | |
| print(total/1024) | |
| if __name__ == "__main__": | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment