Skip to content
Advertisement

Tag: directory

Calculating a directory’s size using Python?

Before I re-invent this particular wheel, has anybody got a nice routine for calculating the size of a directory using Python? It would be very nice if the routine would format the size nicely in Mb/Gb etc. Answer This walks all sub-directories; summing file sizes: And a oneliner for fun using os.listdir (Does not include sub-directories): Reference: os.path.getsize – Gives

Advertisement