NewB: Glob Question

J

J

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)
 
K

kyosohma

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
 
S

Steven D'Aprano

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!

No no, don't tell us what problem you found! We love guessing!!!

Let's see... did it reformat your hard drive? If you join multiple paths
wrong, Python will reformat your hard drive as punishment. I tell you, you
soon learn not to do that!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top