count files in a directory

rbt rbt at athop1.ath.vt.edu
Sat May 21 12:57:25 EDT 2005


James Stroud wrote:
> Sorry, I've never used os.walk and didn't realize that it is a generator.
> 
> This will work for your purposes (and seems pretty fast compared to the 
> alternative):
> 
> file_count = len(os.walk(valid_path).next()[2])

Thanks James... this works *really* well for times when I only need to count files in 
the current directory (no recursion). I think others will find it useful as well.



More information about the Python-list mailing list