List files recursively: use recursive function or os.path.walk()

Andy Gimblett gimbo at ftech.net
Thu Apr 4 05:03:24 EST 2002


On Wed, Apr 03, 2002 at 10:30:14AM -0800, python-list-admin at python.org wrote:
> I want to list all files recursively in a a directory. I can either
> use a recursive function all or use os.path.walk(). I tested both, and
> found that os.path.walk() was actually slightly slower.

[snip]

> conclusions:
> * recursive call is slightly faster than os.path.walk() .
> * code is shorter using os.path.walk() .

To me, that time difference is practically neglible.  Use the code
that's easiest to grok when you look at it again in six months.
Whether that's os.path.walk or your version is up to you, but I'd go
with the standard library every time.

Also, check out the python style guide.  ;-)

-Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.





More information about the Python-list mailing list