-2

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
markov zain
  • 11,987
  • 13
  • 35
  • 39
  • I downvoted because you failed to show any personal application toward the solution. "I want this" without demonstrating any effort to solve it yourself doesn't really gel with my spirit of things. – John Mee Oct 14 '15 at 05:44

1 Answers1

1

Try the below code-

import os
f= r"D:\Reg"
folder_name= os.path.basename(f)
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
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!

Learner
  • 5,192
  • 1
  • 24
  • 36