[Tutor] fnmatch -or glob question

Damon Timm damontimm at gmail.com
Sat Jul 4 02:24:40 CEST 2009


Hi - I am trying to find a group of thumbnail files for deletion --
the files all have similar naming structure (though the details vary).
 When the main file is deleted, I want all the little ones to go too.

For example, here is a directory listing:

DSC_0063.100.jpg
DSC_0063.100x150.jpg
DSC_0063.jpg
DSC_0065.300.jpg
DSC_0065.400x400.jpg
DSC_0065.jpg

Using os.path.splitext and os.path.split I am able to break the files
down into the two parts I need:

base = DSC_0065
ext = .jpg

And I thought I could just construct something for glob or fnmatch like:

glob.glob("DSC_0065*.jpg") --or-- fnmatch.fnmatch(file, "DSC_0065*.jpg")

But I'm not getting anywhere.  I feel like there is something I am
missing in terms of using the wildcard correctly in the middle of a
filename.

Any ideas ?

Thanks,
Damon


More information about the Tutor mailing list