469,292 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,292 developers. It's quick & easy.

NewB: Glob Question

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
2 1220
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
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.

Similar topics

15 posts views Thread by Georgy Pruss | last post: by
5 posts views Thread by Elbert Lev | last post: by
4 posts views Thread by Python Dunce | last post: by
2 posts views Thread by Zain Homer | last post: by
6 posts views Thread by Hitesh | last post: by
3 posts views Thread by billiejoex | last post: by
5 posts views Thread by jo3c | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.