[Tutor] Hard drive searching
Tue, 30 Jan 2001 20:32:38 +0000
On 1/30/01, Matthias Hager wrote about '[Tutor] Hard drive searching':
>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?
Not necessarily elegant, but this should give you the idea...
def fish(suffix_list, dir, file_list):
for file in file_list:
for suffix in suffix_list:
if string.rfind(file, suffix) >= 0:
print dir + file
import os, string
args = ['.html', '.py']
os.path.walk("", fish, args)