rbt wrote:
> Heiko Wundram wrote:
> import os
> path = "/home/heiko"
> file_count = sum((len(f) for _, _, f in os.walk(path)))
> file_count
>
> Thanks! that works great... is there any significance to the underscores
> that you used? I've always used root, dirs, files when using o
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
Heiko Wundram wrote:
> Am Samstag, 21. Mai 2005 06:25 schrieb James Stroud:
>
>>This will work for your purposes (and seems pretty fast compared to the
>>alternative):
>>
>>file_count = len(os.walk(valid_path).next()[2])
>
>
> But will only work when you're just scanning a single directory with
Am Samstag, 21. Mai 2005 06:25 schrieb James Stroud:
> This will work for your purposes (and seems pretty fast compared to the
> alternative):
>
> file_count = len(os.walk(valid_path).next()[2])
But will only work when you're just scanning a single directory with no
subdirectories...!
The altern
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])
The alternative is:
import os
import os.path
file_count = len([f for f in os.listdi
Come to think of it
file_count = len(os.walk(valid_path)[2])
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
--
http://mail.python.org/mailman/listinfo/python-list
On Friday 20 May 2005 07:12 pm, rbt wrote:
> 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
>