count files in a directory

rbt rbt at athop1.ath.vt.edu
Fri May 20 22:12:17 EDT 2005


I assume that there's a better way than this to count the files in a 
directory recursively. Is there???

def count_em(valid_path):
     x = 0
     for root, dirs, files in os.walk(valid_path):
         for f in files:
             x = x+1
     print "There are", x, "files in this directory."
     return x

rbt



More information about the Python-list mailing list