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(sel f):
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.i nsert(END, name)
elif name.endswith(' .gif'): #As well as this
filenames['gif'].append(os.path .join(root, name))
self.listbox1.i nsert(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 4 1486
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.i nsert(END, name) elif name.endswith(' .gif') and 'ocean' in name: filenames['gif'].append(os.path .join(root, name)) self.listbox1.i nsert(END, name)
--
-Scott David Daniels Sc***********@A cm.Org
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.i nsert(END, name) elif name.endswith(' .gif') and 'ocean' in name: filenames['gif'].append(os.path .join(root, name)) self.listbox1.i nsert(END, name)
-- -Scott David Daniels Sc***********@A cm.Org
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
Perhaps better (adds '.png' more easily, keeps original case):
...
for name in files:
lname = name.lower() # if on windows
for ext, names in filenames.iteri tems():
if lname.endswith( ext) and 'ocean' in name:
names.append(os .path.join(root , name))
self.listbox1.i nsert(END, name)
break
...
--
-Scott David Daniels Sc***********@A cm.Org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
users, supposedly) to upload their files to their designaged
directories (max 15 files for each user). A super user (can be more
than one) want to search for a particular file name and also a
particular textual part of a file of all user's files in all...
|
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) for my pupils.
This very simple thing does not seem simple at all.
If I use strings, I cannot replace their parts (though I can use
string.find for the searching). I think it is a bad idea that strings are
not mutable, but I suspect that...
|
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 'myvar'. however, it
doesn't seem to be seeing it... Here's a snippet.
import re
# list of items to search...
mylist =
# my variable I want to search with...
|
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 different
story.
Linked lists have been giving me a headache. I can barely manage to
create a single/doubly linked list, it's just that when it gets to
merge sorting or searching (by reading shit data from text files), I
lose track.
|
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 be great if the engine (or so) would accept multiple parameters (like a search offset, a max number of bytes to search in etc.)
Any ideas
Thanks a lot again
Gordon
| |
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 criteria:
I have a list of about 100 numbers which correspond to the ID field and also
another 40 say numbers corresponding to the numbers in the PRODUCT field. I
want to show the rows that correspond to both these criteria.
|
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 three
bolded periods '...' in search-result listings.
Additionally, most content is outdated; as many users need up-to-date
content. Hence, filtering-through search-results becomes quite
cumbersome.
The newsgroup listings allow detailed...
|
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 string will often not produce a direct match,
the results will be based on proximity (50%, 20% 100%, etc).
are there any good examples out there on how to do keyword
searches on XML data? How should i set up my xml file so
|
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 search algorithms that can be used are Linear Search and Binary Search. The sorting algorithms are bubble, selection and Insertion sort.
First, the user is asked whether he/she wants to perform a search option, a sort operation, or exit the program. If...
|
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 matches
\\.+?\b (something started by a backslash and including the word that
follows).
More concrete example, I have the string "\sin(i)" and I want to match
the argument, but not the i in \sin.
Can this be achieved by combining the regular...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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 we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |