I'm sorry. I didn't mean to offend you. I never thought your way was
inferior.
Justin Azoff wrote:
> [EMAIL PROTECTED] wrote:
> > I do appreciate the advice, but I've got a 12 line function that does
> > all of that. And it works! I just wish I understood a particular line
> > of it.
>
> You
[EMAIL PROTECTED] wrote:
> I do appreciate the advice, but I've got a 12 line function that does
> all of that. And it works! I just wish I understood a particular line
> of it.
>
> def getFileList(*extensions):
> import os
> imageList = []
> for dirpath, dirnames, files in os.walk('.
[EMAIL PROTECTED] wrote:
> I do appreciate the advice, but I've got a 12 line function that does
> all of that. And it works! I just wish I understood a particular line
> of it.
You miss the point. The functions I posted, up until get_files_by_ext
which is the equivalent of your getFileList, to
I do appreciate the advice, but I've got a 12 line function that does
all of that. And it works! I just wish I understood a particular line
of it.
def getFileList(*extensions):
import os
imageList = []
for dirpath, dirnames, files in os.walk('.'):
for filename in files:
[EMAIL PROTECTED] wrote:
> I've narrowed down the problem. All the problems start when I try to
> eliminate the hidden files and directories. Is there a better way to
> do this?
>
Well you almost have it, but your problem is that you are trying to do
too many things in one function. (I bet I am
That worked perfectly. Thank you. That was exactly what I was looking
for. However, can you explain to me what the following code actually
does?
reversed(range(len(dirnames)))
Gabriel Genellina wrote:
> At Tuesday 8/8/2006 21:11, [EMAIL PROTECTED] wrote:
>
>
> >Here's my code:
> >
> >def getF
I've narrowed down the problem. All the problems start when I try to
eliminate the hidden files and directories. Is there a better way to
do this?
[EMAIL PROTECTED] 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 file
At Tuesday 8/8/2006 21:11, [EMAIL PROTECTED] 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:
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.
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('.'):
[EMAIL PROTECTED] wrote:
[...]
> that? And also, I'm still not sure I know exactly how os.walk() works.
> And, finally, the python docs all note that symbols like . and ..
> don't work with these commands. How can I grab the directory that my
> script is residing in?
os.getcwd() will get you th
> Also, I've noticed that files are being found within hidden
> directories. I'd like to exclude hidden directories from the walk, or
> at least not add anything within them. Any advice?
The second item in the tuple yielded by os.walk() is a list of
subdirectories inside the directory indicated
[EMAIL PROTECTED] wrote:
> Okay. This is almost solved. I just need to know how to have each
> entry in my final list have the full path, not just the file name.
from http://docs.python.org/lib/os-file-dir.html:
walk() generates the file names in a directory tree, by walking the
tree either top
[EMAIL PROTECTED] wrote:
> And, finally, the python docs all note that symbols like . and ..
> don't work with these commands.
Where did you read that? The docs for os.listdir do say that '.' and
'..' are (sensibly) not returned as *results*. AFAIK there is nothing
to stop you using '.' or '..'
At Tuesday 8/8/2006 17:55, [EMAIL PROTECTED] wrote:
I must ask, in the interest of learning, what is
[file for file in files if file.endswith(extension)]
actually doing? I know that 'file' is a type, but what's with the set
up and the brackets and all? Can someone run down the syntax for me
Okay. This is almost solved. I just need to know how to have each
entry in my final list have the full path, not just the file name.
Also, I've noticed that files are being found within hidden
directories. I'd like to exclude hidden directories from the walk, or
at least not add anything within
[EMAIL PROTECTED] wrote:
> I must ask, in the interest of learning, what is
>
> [file for file in files if file.endswith(extension)]
>
> actually doing? I know that 'file' is a type, but what's with the set
> up and the brackets and all?
Other people explained the list comprehension, but you m
[EMAIL PROTECTED] wrote:
> hiaips wrote:
> > > [EMAIL PROTECTED] 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
So far, so good. I just have a few more questions.
Here's my code so far:
import os
top = '/home/USERNAME/'
images = []
for files in os.walk(top, topdown=True):
images += [file for file in files[2] if file.endswith('jpg')]
print images
I still need to know how I can dynamically get the
Oops, what I wrote above isn't quite correct. As another poster pointed
out, you'd want to do
for file in x[2]:
...
--dave
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> Thanks, Dave. That's exactly what I was looking for, well, except for
> a few small alterations I'll make to achieve the desired effect. I
> must ask, in the interest of learning, what is
>
> [file for file in files if file.endswith(extension)]
>
> actually doing? I k
[EMAIL PROTECTED] wrote:
> Mike Kent wrote:
> > What you want is os.walk().
> >
> > http://www.python.org/doc/current/lib/os-file-dir.html
>
> I'm thinking os.walk() could definitely be a big part of my solution,
> but I need a little for info. If I'm reading this correctly, os.walk()
> just goes
Thanks, Dave. That's exactly what I was looking for, well, except for
a few small alterations I'll make to achieve the desired effect. I
must ask, in the interest of learning, what is
[file for file in files if file.endswith(extension)]
actually doing? I know that 'file' is a type, but what's
> I'm thinking os.walk() could definitely be a big part of my solution,
> but I need a little for info. If I'm reading this correctly, os.walk()
> just goes file by file and serves it up for your script to decide what
> to do with each one. Is that right? So, for each file it found, I'd
> have
Mike Kent wrote:
> What you want is os.walk().
>
> http://www.python.org/doc/current/lib/os-file-dir.html
I'm thinking os.walk() could definitely be a big part of my solution,
but I need a little for info. If I'm reading this correctly, os.walk()
just goes file by file and serves it up for your s
> [EMAIL PROTECTED] 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 t
[EMAIL PROTECTED] 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.
What you want is os.walk().
http://www.python.org/doc/current/lib/os-file-d
Hey, I've done similar things.
You can use system comands with the following
import os
os.system('command here')
You'd maybe want to do something like
dir_name = 'mydirectory'
import os
os.system('ls ' +dir_name + ' > lsoutput.tmp')
fin = open('lsoutput.tmp', 'r')
file_list = fin.readlines()
fi
Hey, I've done similar things.
You can use system comands with the following
import os
os.system('command here')
You'd maybe want to do something like
dir_name = 'mydirectory'
import os
os.system('ls ' +dir_name + ' > lsoutput.tmp')
fin = open('lsoutput.tmp', 'r')
file_list = fin.readlines()
fi
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
30 matches
Mail list logo