Created
July 30, 2019 12:07
-
-
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.
This file contains 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
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