By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

NewB: Glob Question

P: n/a
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)

May 3 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 3, 12:38 pm, J <wilder.use...@gmail.comwrote:
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

May 3 '07 #2

P: n/a
On Thu, 03 May 2007 10:38:31 -0700, J 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!
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!

--
Steven D'Aprano

May 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.