NewB: Glob Question

kyosohma at gmail.com kyosohma at gmail.com
Thu May 3 14:40:17 EDT 2007


On May 3, 12:38 pm, J <wilder.use... at gmail.com> wrote:
> Greetings Group-
>
> I'm trying to put together a pattern matching script that scans a
> directory tree for tif images contained in similar folder names, but
> running into a NewB problem already. Is it the way I'm trying to join
> multiple paths? Any help would be greatly appericated. Thanks, J!
>
> import glob, sys, os
>
> topdir = sys.argv[1]
> tifFilter = '*.tif'
> dirFilter = '**'
>
> tifList = glob.glob(os.path.join(topdir, tifFilter))
> tifList = tifList + glob.glob(os.path.join(topdir, dirFilter,
> tifFilter))
>
> for tif in tifList:
>        print os.basename(tif) + " is in " + os.dirname(tif)

I messed around with this some and I believe you are correct. When you
tell it to search using '**', glob will look only in directories that
are two characters long. This is obviously not what is needed.
Instead, try setting it like this:

dirFilter = '*\\'

That seemed to work for me.

Good luck!

Mike




More information about the Python-list mailing list