Reputation: 1700
How to count size of a directory using os.walk()
python?
I could get all the root files using below code-
root = "/dbfs/mnt/datalake/Persistent/External/"
for path, subdirs, files in os.walk(root):
for name in files:
print (os.path.join(path, name))
But I need total directory size of "External". How can I achieve this?
Upvotes: 2
Views: 599
Reputation: 27577
Like this?
import os
size=0
root = "/dbfs/mnt/datalake/Persistent/External/"
for path, subdirs, files in os.walk(root):
for name in files:
size+=os.path.getsize(os.path.join(path, name))
print(size)
Upvotes: 2