Need a recursion lesson
Robert Roy
rjroy at takingcontrol.com
Tue Dec 21 22:38:26 EST 1999
On Wed, 22 Dec 1999 03:33:44 +0100, "Eide" <nickliz at t-online.de>
wrote:
>Hello,
>I would like to do a search for file types, and I figure a good way to do it
>would be with recursion... compare a sliced 'file[:-6]' of each item in
>list from a directory. And if there is another directory in that list to do
>a listdir on it and .... My head is spinning already.
>I have no clue what I'm doing. Does anyone have any pointers to about how to
>walk through something like this? Any help would be a lot.
>
>Nick
>
>
No need to re-invent the wheel, see the os.path module
import os
def visit(arg, dirname, names):
print dirname
for fn in names:
name, ext = os.path.splitext(fn)
print ext
os.path.walk('c:/temp',visit, ())
More information about the Python-list
mailing list