Skip to content

Commit 980cc85

Browse files
committed
fix error in folder size calculator where files do not exist in some cases
1 parent 4ce02df commit 980cc85

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

general/calculate-directory-size/get_directory_size.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ def get_directory_size(directory):
2727
total += entry.stat().st_size
2828
elif entry.is_dir():
2929
# if it's a directory, recursively call this function
30-
total += get_directory_size(entry.path)
30+
try:
31+
total += get_directory_size(entry.path)
32+
except FileNotFoundError:
33+
pass
3134
except NotADirectoryError:
3235
# if `directory` isn't a directory, get the file size then
3336
return os.path.getsize(directory)

0 commit comments

Comments
 (0)