Searching
ADE
na
Mon Feb 9 10:45:54 EST 2004
Hi I was wondering if one of you could help me out
I would like for this function to be able to find file names as well instead
of printing out every file that ends with a .jpg or .gif extension
but I don't know how to use reg expressions and yes I have been trying to
figure them out for the past day and a half now
def searchfiles(self):
filenames = {'jpg': [], 'gif': []}
path = 'S:/'
for root, dirs, files in os.walk(path):
for name in files:
# This is the part that needs to be changed I just don't know
how to do it
if name.endswith('.jpg'): # right here this should be what
needs to be changed
filenames['jpg'].append(os.path.join(root, name))
self.listbox1.insert(END, name)
elif name.endswith('.gif'): #As well as this
filenames['gif'].append(os.path.join(root, name))
self.listbox1.insert(END, name)
I should let you know that this is a function attached to a button that
searches my harddrive for files it has an entry field to do the searching
but it prints out every image file I want to limit it the name typed in eg
if I type ocean every file with the name ocean appears
More information about the Python-list
mailing list