Re: newb question: file searching
- From: "jaysherby@xxxxxxxxx" <jaysherby@xxxxxxxxx>
- Date: 8 Aug 2006 17:18:21 -0700
Something's really not reliable in my logic. I say this because if I
change the extension to .png then a file in a hidden directory (one the
starts with '.') shows up! The most frustrating part is that there are
..jpg files in the very same directory that don't show up when it
searches for jpegs.
I tried os.walk('.') and it works, so I'll be using that instead.
jaysherby@xxxxxxxxx wrote:
Here's my code:
def getFileList():
import os
imageList = []
for dirpath, dirnames, filenames in os.walk(os.getcwd()):
for filename in filenames:
for dirname in dirnames:
if not dirname.startswith('.'):
if filename.lower().endswith('.jpg') and not
filename.startswith('.'):
imageList.append(os.path.join(dirpath, filename))
return imageList
I've adapted it around all the much appreciated suggestions. However,
I'm running into two very peculiar logical errors. First, I'm getting
repeated entries. That's no good. One image, one entry in the list.
The other is that if I run the script from my Desktop folder, it won't
find any files, and I make sure to have lots of jpegs in the Desktop
folder for the test. Can anyone figure this out?
jaysherby@xxxxxxxxx wrote:
I'm new at Python and I need a little advice. Part of the script I'm
trying to write needs to be aware of all the files of a certain
extension in the script's path and all sub-directories. Can someone
set me on the right path to what modules and calls to use to do that?
You'd think that it would be a fairly simple proposition, but I can't
find examples anywhere. Thanks.
.
- References:
- newb question: file searching
- From: jaysherby@xxxxxxxxx
- Re: newb question: file searching
- From: jaysherby@xxxxxxxxx
- newb question: file searching
- Prev by Date: Re: beginner questions on embedding/extending python with C++
- Next by Date: Re: beginner questions on embedding/extending python with C++
- Previous by thread: Re: newb question: file searching
- Next by thread: Re: newb question: file searching
- Index(es):
Relevant Pages
|