#!/usr/bin/env python # -*- coding: utf-8 -*- import sys, os, stat import time
def main(root): dirsize = {} for dirpath, dirnames, filenames in os.walk(root.decode('cp932'), topdown=False): dirsize[dirpath] = 0 for file in filenames: tgt = os.path.join(dirpath, file) siz = os.stat(tgt)[stat.ST_SIZE] dirsize[dirpath] += siz for dir in dirnames: tgt = os.path.join(dirpath, dir) siz = dirsize[tgt] dirsize[dirpath] += siz print u'"dir","%s",%d' % (tgt, siz)
print u'"total","%s",%d' % (root, dirsize[root])
if __name__ == '__main__': if len(sys.argv) >= 2: main(sys.argv[1])