Answers for "get files size in a folder python"

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 "get files size in a folder python"

Python Answers by Framework

Browse Popular Code Answers by Language