[Tutor] Hard drive searching

Doug Stanfield DOUGS@oceanic.com
Tue, 30 Jan 2001 09:55:44 -1000

You might find that the best way is to let the operating system do the hard
work.  It is usually optimised to do things like this.  You can then use
Python to deal with the results of the search.

How would you do this task if you were at a command prompt.  On a Linux
system I'd do something with 'locate' or 'find'.  To use that in Python look
into the os.popen
(http://www.python.org/doc/current/lib/os-newstreams.html#l2h-907) or
os.spawnv (http://www.python.org/doc/current/lib/os-process.html#l2h-995)
functions.  If you're on windows, popen in particular only works reliably
with Python 2.0 or better.



> -----Original Message-----
> From: Kalle Svensson [mailto:kalle@gnupung.net]
> Sent: Tuesday, January 30, 2001 9:46 AM
> To: Matthias Hager
> Cc: tutor@python.org
> Subject: Re: [Tutor] Hard drive searching
> Sez Matthias Hager:
> > I've been thinking about this for awhile, but can't figure 
> anything out.
> > What I need my python program to do is, go through my hard drive, as
> > quickly as possible, and return all the files that end with 
> a certain
> > extension(like .html or .py). How could I do this?   
> You might want to look at os.path.walk().  Otherwise, I have 
> no great ideas
> at this time.
> Peace,
>   Kalle
> -- 
> Email: kalle@gnupung.net     | You can tune a filesystem, but you
> Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
> PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD