/ Published in: Python

this will display the size of a directory as if you run du -sb dir
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def _total_size(source): total_size = os.path.getsize(source) for item in os.listdir(source): itempath = os.path.join(source, item) if os.path.isfile(itempath): total_size += os.path.getsize(itempath) elif os.path.isdir(itempath): total_size += self._total_size(itempath) return total_size
Comments
