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 glob
jpgList = glob.glob("*.jpg") # the glob allows you to use wild cards in the
search
jpgCount = len(jpgList)
This gives you a list of all files that end in .jpg.  You can then do a
len(jpgList) to get the number of files
John

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 for .jpg, .JPG, .jpeg, *and* .JPEG?

-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to