473,498 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching

ADE
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

Jul 18 '05 #1
4 1469
ADE wrote:
Hi I was wondering if one of you could help me out You are missing info on your system and python version.
If you are running 2.3 or later:...
for name in files:
name = name.lower() # if on windows
if name.endswith('.jpg') and 'ocean' in name:
filenames['jpg'].append(os.path.join(root, name))
self.listbox1.insert(END, name)
elif name.endswith('.gif') and 'ocean' in name:
filenames['gif'].append(os.path.join(root, name))
self.listbox1.insert(END, name)


--
-Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #2
ADE
Hi sorry about that I am running Python 2.3 and Windows XP

"Scott David Daniels" <Sc***********@Acm.Org> wrote in message
news:40********@nntp0.pdx.net...
ADE wrote:
Hi I was wondering if one of you could help me out

You are missing info on your system and python version.
If you are running 2.3 or later:
...
for name in files:
> name = name.lower() # if on windows
if name.endswith('.jpg') and 'ocean' in name:
filenames['jpg'].append(os.path.join(root, name))
self.listbox1.insert(END, name)
elif name.endswith('.gif') and 'ocean' in name:
filenames['gif'].append(os.path.join(root, name))
self.listbox1.insert(END, name)


--
-Scott David Daniels
Sc***********@Acm.Org

Jul 18 '05 #3
Hello,
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

Have a look at the `glob' module.

HTH.
Miki
Jul 18 '05 #4
Perhaps better (adds '.png' more easily, keeps original case):
...
for name in files:
lname = name.lower() # if on windows
for ext, names in filenames.iteritems():
if lname.endswith(ext) and 'ocean' in name:
names.append(os.path.join(root, name))
self.listbox1.insert(END, name)
break
...
--
-Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2510
by: John | last post by:
Hi everyone ! This is a first time I post a message here. If I post my message in a wrong group. Please ignore it. I am trying to build a website which allows users (can be thousands of...
18
2485
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
4
1792
by: tgiles | last post by:
Hi, all. Another bewildered newbie struggling with Python goodness. This time it's searching strings. The goal is to search a string for a value. The string is a variable I assigned the name...
2
8234
by: Kakarot | last post by:
I'm gona be very honest here, I suck at programming, *especially* at C++. It's funny because I actually like the idea of programming ... normally what I like I'm atleast decent at. But C++ is a...
8
2343
by: Gordon Knote | last post by:
Hi can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++). The search should be as fast as possible and it would...
33
2430
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
5
2380
by: justobservant | last post by:
When more than one keyword is typed into a search-query, most of the search-results displayed indicate specified keywords scattered throughout an entire website of content i.e., this is shown as...
7
2603
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
5
3164
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
2
1500
by: Bart Kastermans | last post by:
I have a file in which I am searching for the letter "i" (actually a bit more general than that, arbitrary regular expressions could occur) as long as it does not occur inside an expression that...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.