Iterating over files of a huge directory

Gilles Lenfant gilles.lenfant at gmail.com
Mon Dec 17 16:28:46 CET 2012


Hi,

I have googled but did not find an efficient solution to my problem. My customer provides a directory with a huuuuge list of files (flat, potentially 100000+) and I cannot reasonably use os.listdir(this_path) unless creating a big memory footprint.

So I'm looking for an iterator that yields the file names of a directory and does not make a giant list of what's in.

i.e :

for filename in enumerate_files(some_directory):
    # My cooking...

Many thanks by advance.
-- 
Gilles Lenfant



More information about the Python-list mailing list