Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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

Re: newb question: file searching

2006-08-08 Thread John Machin
[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('.

Re: newb question: file searching

2006-08-08 Thread Justin Azoff
[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

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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:

Re: newb question: file searching

2006-08-08 Thread Justin Azoff
[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

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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

Re: newb question: file searching

2006-08-08 Thread Gabriel Genellina
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:

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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.

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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('.'):

Re: newb question: file searching

2006-08-08 Thread thebjorn
[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

Re: newb question: file searching

2006-08-08 Thread infidel
> 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

Re: newb question: file searching

2006-08-08 Thread Steve M
[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

Re: newb question: file searching

2006-08-08 Thread John Machin
[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 '..'

Re: newb question: file searching

2006-08-08 Thread Gabriel Genellina
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

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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

Re: newb question: file searching

2006-08-08 Thread Steve M
[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

Re: newb question: file searching

2006-08-08 Thread Simon Forman
[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

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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

Re: newb question: file searching

2006-08-08 Thread hiaips
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

Re: newb question: file searching

2006-08-08 Thread hiaips
[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

Re: newb question: file searching

2006-08-08 Thread Jason
[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

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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

Re: newb question: file searching

2006-08-08 Thread hiaips
> 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

Re: newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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

Re: newb question: file searching

2006-08-08 Thread hiaips
> [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

Re: newb question: file searching

2006-08-08 Thread Mike Kent
[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

Re: newb question: file searching

2006-08-08 Thread godavemon
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

Re: newb question: file searching

2006-08-08 Thread godavemon
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

newb question: file searching

2006-08-08 Thread [EMAIL PROTECTED]
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