regular expressions eliminating filenames of type foo.thumbnail.jpg

oscartheduck oscartheduck at gmail.com
Mon Jun 25 17:41:04 EDT 2007


I eventually went with:

#!/usr/bin/env python
from PIL import Image
import glob, os, re

size = 128, 128

def thumbnailer(dir, filenameRx):
     for picture in [ p for p in os.listdir(dir) if
os.path.isfile(os.path.join(
 dir,p)) and filenameRx.match(p) if 'thumbnail' not in p]:
         file, ext = os.path.splitext(picture)
         im = Image.open (picture)
         im.thumbnail(size, Image.ANTIALIAS)
         im.save(file + ".thumbnail" + ext)

jpg = re.compile(".*\.(jpg|jpeg)", re.IGNORECASE)
thumbnailer(".", jpg)


Thanks for the help!






More information about the Python-list mailing list