I want to ask how to calculate 3 folder size together using python and show as dataframe.
I have folder: A B C
The output that i want is:
folder size
A .... byte
B .... byte
C .... byte
I want to ask how to calculate 3 folder size together using python and show as dataframe.
I have folder: A B C
The output that i want is:
folder size
A .... byte
B .... byte
C .... byte
Try the below code-
import os
f= r"D:\Reg"
folder_name= os.path.basename(f)
def get_size(start_path = '.'):total_size = 0for 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
print "{0:<20} {1:>0}".format("Folder"," Size")
print "{0:<20} {1:>0}".format(folder_name,str(get_size(f))+" bytes")
You can use looping for folder folders = [r"D:\A",r"D:\B",r"D:\C"]
as for i in folders do that!