I have written a python script where I am trying to find the size of a sub-directory where I can only define the base path of the directory and need to traverse for the folder whose size I want to check. I am able to print that particular directory but size of that directory is showing O MB while it is 31MB folder. What could be I missing. Please help.
# determine size of a given folder in MBytes
import os
# pick base path you have ...
for root, dirs, files in os.walk('E:\pkg'):
Total_size = 0
for dir in dirs:
if dir.startswith('mobile'):
dir = os.path.join(root, dir)
Total_size = os.path.getsize(dir)
print(dir)
print("Size = %0.1f MB" % (Total_size / (1024 * 1024.0)))