[Tutor] Replacement for 'Find' Module

Simon Gerber nequeo at gmail.com
Mon Aug 15 09:46:02 CEST 2005

You could probably do something like this... (Note: This example is
for Linux - but you can adapt it fairly easily to Windows.)

# E.g. Find every .inf file on a CD-ROM.
path = '/cdrom'  
# 'E:\\' or whatever for Windows.... 
inf_list = []
for root, dirs, files in os.walk(path):
    for current_file in files:
        if '.inf' in current_file:
           inf_list.append(os.path.join(root, current_file))

I, too, would be interested in knowing if anyone has a better way to do this :)
You would probably combine the 'glob' module with os.walk to grab what
you wanted, and build the list of files that way.

Lemme know what you figure out.


On 15/08/05, Don Parris <gnumathetes at gmail.com> wrote:
> On my Windows XP box running Python 2.4, I attempted to use the 'find'
> module per the example in Programming Python (Ch. 2) - i.e.:
> >>>import find
> >>>find.find('*')
> However, Python didn't find the find module.  The docs say it's now
> deprecated, but don't point to what tool should be used to replace
> find.  My Googling efforts haven't been fruitful so far.  Could
> someone please point me in the right direction?
> Don
> --
> DC Parris GNU Evangelist
> http://matheteuo.org/
> gnumathetes at gmail.com
> "Hey man, whatever pickles your list!"
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list