On Wednesday 12 October 2005 19:10, Marc Buehler wrote:
> i would like to extract the number of JPG files
> from the current directory and use that number
I've looked through the thread, and the following strikes me as simpler than
the suggestions so far.
path = "." # Current directory, unix at
>> a = len(os.listdir(mydir, '*JPG')
>>
>> Should be about right...
>
> No, os.listdir() only takes one argument, the directory. See the solutions
> with glob.glob().
Oops! Quite right, my mistake. (As is the missing right paren!)
Alan g.
___
Tutor m
> glob seems to be a good idea, ...
Yep, I got my glob and listdir mixed up earlier...
> it may be slower than glob, but i'm finding myself thinking more like...
> len([i for i in os.listdir('tmp') if i.lower().endswith('.jpg')])
>
> now, anyone with a solution for .jpg, .JPG, .jpeg, *and* .JPEG?
Alan Gauld wrote:
> a = len(os.listdir(mydir, '*JPG')
>
> Should be about right...
No, os.listdir() only takes one argument, the directory. See the solutions with
glob.glob().
Kent
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailma
> a = os.system('ls *JPG | wc -l')
> when i do:
> print a
> i get '0'.
os.system only returns the exitcode of the command not the output.
Look at the new Subprocess module and its Popen class. It can
look intimidating at first but read the examples and you should find
it easy enough.
Altrerna
w chun wrote:
> glob seems to be a good idea, but is there a way to do it
> case-insensitively, i.e., .jpg and .JPG?
>
> it may be slower than glob, but i'm finding myself thinking more like...
>
> len([i for i in os.listdir('tmp') if i.lower().endswith('.jpg')])
>
> now, anyone with a solution
On 10/12/05, Ertl, John <[EMAIL PROTECTED]> wrote:
You can do most system type stuff in Python and it makes it much easier.import globjpgList = glob.glob("*.jpg") # the glob allows you to use wild cards in thesearchjpgCount = len(jpgList)This gives you a list of all files that end in .jpg. You can
I think os.system returns status of commands
Try this:
w = os.popen('ls -l | wc -l').readlines()
Python Newbie...
On Wednesday 12 October 2005 12:10 pm, Marc Buehler wrote:
> hi.
>
> i'm new to Python ...
>
> i would like to extract the number of JPG files
> from the current directory and use th
to get the number of files
John
-Original Message-
From: Marc Buehler [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 12, 2005 11:10 AM
To: tutor@python.org
Subject: [Tutor] how to extract number of files from directory
hi.
i'm new to Python ...
i would like
Marc Buehler wrote:
> i would like to extract the number of JPG files
> from the current directory and use that number
> as a parameter in my python script.
> i tried:
> a = os.system('ls *JPG | wc -l')
> when i do:
> print a
> i get '0'.
>
> what am i missing?
os.system() returns the exit code
hi.
i'm new to Python ...
i would like to extract the number of JPG files
from the current directory and use that number
as a parameter in my python script.
i tried:
a = os.system('ls *JPG | wc -l')
when i do:
print a
i get '0'.
what am i missing?
marc
---
11 matches
Mail list logo