searching for files on Windows with Python
Kent Johnson
kent37 at tds.net
Thu Nov 17 16:10:04 EST 2005
Shane wrote:
> I've been giving Google a good workout with no luck. I would like to
> be able to search a Windows filesystem for filenames, returning a
> list off absolute paths to the found files, something like:>
> def findFiles(filename, pathToSearch):
> ...
> ...
> return foundFileNames
>
> Is the os module where I should start?
I always use Jason Orendorff's path module for this kind of stuff. It's way easier to use than os.whatever:
import path
files = path.path(pathToSearch).walkfiles(filename)
will give a list of path.path objects in pathToSearch whose names match filename (which is a glob so wildcards are recognized).
path.path is a subclass of str so the results can be used wherever you want the full path.
http://www.jorendorff.com/articles/python/path/index.html
Kent
More information about the Python-list
mailing list