Answers for "python check the size of a directory"

3

how to get size of folder 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)
            # skip if it is symbolic link
            if not os.path.islink(fp):
                total_size += os.path.getsize(fp)

    return total_size

print(get_size(), 'bytes')
Posted by: Guest on April-17-2020

Code answers related to "python check the size of a directory"

Python Answers by Framework

Browse Popular Code Answers by Language