is there a better way to walk a file system?

Peter Hansen peter at engcorp.com
Fri Jul 1 12:00:14 EDT 2005


ina wrote:
> I want to walk a folder structor and group all the files by extention.
> 
> Here is the code I put together is there a better way of doing this?
> <code>
[snip]

If you were to download Jason Orendorff's "path" module, which is a 
convenient single-file package that vastly simplifies all manner of 
dealings with directory and file names, I suspect your example code 
could be reduced to less than half the number of lines it now uses, and 
with a corresponding increase in readability and maintainability.

The answer to the question "is there a better way of doing this?" in 
relation to paths is always "yes, use Jason Orendorff's path module".

-Peter



More information about the Python-list mailing list