I've run into an issue with glob and matching filenames with brackets '[]'
in them. The problem comes when I'm using part of such a filename as the
path I'm passing to glob. Here's a trimmed down dumb example. Let's say I
have a directory with the following files in it.
foo.par2
foo.vol0+1.par2
foo.vol1+1.par2
zzz [foo].par2
zzz [foo].vol0+1.par2
zzz [foo].vol1+1.par2
While processing one of the files I want to do certain things in batch so
I've been using glob as a means to get all of the files in a set. The
following code will print the filenames for parity volumes in each set
while working with the base checksum, unless there are brackets in the
name.
#re2 = re.compile(r'vol', re.IGNORECASE)
#for nuke in glob.glob('*.par2'):
# if not re2.search(nuke):
# list = glob.glob(nuke[:-5]+'*vol*')
# for name in list: print os.path.join(os.getcwd(),name)
I'm sure there is something obvious I'm missing. I figured I could use
something like re.escape on the trimmed filename for matching but that
hasn't worked either. Using win32api.FindFiles instead of glob works but
I'd obviously rather do it the _right_ way and have it work properly in
*nix too.