def get_size ( path ) : if os . path . isfile ( path ) : return os . path . getsize ( path ) return sum ( get_size ( os . path . join ( path , f ) ) for f in os . listdir ( path ) )
get size for files in directory in python
Returns the size in bytes if path is a file or the size of all files in path if it s a directory . Analogous to du - s .
def get_size(path):
    """ Returns the size in bytes if `path` is a file,
        or the size of all files in `path` if it's a directory.
        Analogous to `du -s`.
    """
    if os.path.isfile(path):
        return os.path.getsize(path)
    return sum(get_size(os.path.join(path, f)) for f in os.listdir(path))