I work with one big directory (Project) that divided into 3 subfolders (a, lyr, out) and they divided into sub-subfolders with a lot of files inside them:
I try to get the size of those 3 sub folders- each subfolder separately. When i using this code (i red Calculating a directory size using Python?):
import os
def get_size(start_path = "."):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
path = r"G:\desktop\Project"
dirList = os.listdir(path)
for fname in dirList:
print fname
print get_size(path)
i get:
>>>
a
41730716
lyr
41730716
out
41730716
>>>
I don't understand what is my mistake.
41730716 is the size of all "Project" directory, and this is not what i want. I need the size of subfolders: a, lyr, out each. Actually, the size of subfolder a is 23.4 MB ,lyr is 12 MB ,out is 4 MB- those values i need to get in the result.
I red: in Calculating size folder python. in this question, i got only the directory size including all subfolders size- that isn't what i need.