Skip to content

Instantly share code, notes, and snippets.

@liaoyw
Forked from jon-uw/filesize_sum.py
Last active August 29, 2015 14:09
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 liaoyw/d7ac8a4119a6620886ca to your computer and use it in GitHub Desktop.
Save liaoyw/d7ac8a4119a6620886ca to your computer and use it in GitHub Desktop.
import os
"""
as bash command: du -sb dir
+4906: add 4096bytes for the top dir
"""
def du_sb(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)])) + 4096;
def get_total_file_size(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)]) if os.path.isfile(f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment