Pages

Sunday, May 15, 2011

Python count files in dirs program; better ls | wc -l (word count)

#!/usr/bin/python

import os
from os.path import join, getsize
for root, dirs, files in os.walk('.'):
    print root, "consumes",
    print sum(getsize(join(root, name)) for name in files),
    print "bytes in", len(files), "non-directory files"

No comments:

Post a Comment