Faster os.walk()

Kent Johnson kent37 at tds.net
Wed Apr 20 13:22:14 EDT 2005


fuzzylollipop wrote:
> after extensive profiling I found out that the way that os.walk() is
> implemented it calls os.stat() on the dirs and files multiple times and
> that is where all the time is going.

os.walk() is pretty simple, you could copy it and make your own version that calls os.stat() just 
once for each item. The dirnames and filenames lists it yields could be lists of (name, 
os.stat(path)) tuples so you would have the sizes available.

Kent



More information about the Python-list mailing list