Bring value from walk()

Gerrit Holl gerrit.holl at
Fri Feb 25 07:50:51 EST 2000

<quote name="Milos Prudek" date="951477167">
> I need a function that walks the dir tree and adds up occupied space.

class DiskUsage:
    __size = 0

    def adddir(self, dir):
        files = os.listdir(dir)
        dirs = []
        for file in files:
            filename = os.path.join(dir, file)
            s = os.lstat(filename)
            mode = s[ST_MODE]
            if S_ISDIR(mode):
            elif S_ISREG(mode):
                self.__size = self.__size + s[ST_SIZE]
        for dir in dirs:

    def len(self):
        return self.__size

def du(dir):
    '''du(dir) -> int

    Returns the size in bytes of 'dir'.

    disk = DiskUsage()
    return disk.len()

Comparison Python GUI's:
Please comment!

More information about the Python-list mailing list