Skip to content

Instantly share code, notes, and snippets.

@zero-shubham
Created July 30, 2019 12:07
Show Gist options
  • Save zero-shubham/de47cfb332b9007950f6c4ae88d85f62 to your computer and use it in GitHub Desktop.
Save zero-shubham/de47cfb332b9007950f6c4ae88d85f62 to your computer and use it in GitHub Desktop.
This recursive function written in python3 returns the total size of a directory.
import os
def recursive_dir_size(path):
size = 0
for x in os.listdir(path):
if not os.path.isdir(os.path.join(path,x)):
size += os.stat(os.path.join(path,x)).st_size
else:
size += recursive_dir_size(os.path.join(path,x))
return size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment