Dumb glob question
Python Dunce
PDunce at somewhere.invalid
Mon Feb 7 20:06:11 EST 2005
"wittempj at hotmail.com" <wittempj at hotmail.com> wrote in comp.lang.python:
> code like below willprint all files ending on 'par2', except tose not
> containong 'vol' from the 5th position. is that what you need?
> -import glob
> -for nuke in glob.glob(r"""c:\temp\*.par2"""):
> - try:
> - nuke.index('vol', 5)
> - print nuke
> - except ValueError, e:
> - print e
Not quite. I'm sorry my example wasn't very clear. While working with any
single file I need to be able to build a list of all the other files in a
particular set. Basically I just need globbing of the base filename.
glob.glob(basename+'.*some_extension')
So if I was working with 'foo.par2' at the moment...
glob.glob(filename[:-5]+'.*par2')
would catch all of the files belonging to the set including 'foo.par2'
'foo.vol0+1.par2' 'foo.vol1+1.par2' etc.
This works great (as expected) until you are working with a filename with
brackets '[]' in it. Then glob just returns an empty list. So if I happen
to be processing 'foo [bar].par2'
glob.glob(filename[:-5]+'.*par2')
doesn't return anything. Using win32api.FindFiles(filename[:-5]+'.*par2')
works perfectly, but I don't want to rely on win32api functions. I hope
that made more sense :).
More information about the Python-list
mailing list