glob & fnmatch unable to match dirs/files containing [ ] ?

Peter Hansen peter at engcorp.com
Sun Mar 23 00:33:45 CET 2003


Steven Taschuk wrote:
> 
> Quoth Robert:
>   [...]
> > quoting attempts don't work:
> >
> > >>> glob.glob(  r'testsync\[2\]/*'  )            # or  'testsync\\[2\\]/*'
> > []
> 
> You can quote the '[' by putting it in a character class of its
> own:
>         >>> glob.glob('testsync[[]2]')
>         ['testsync[2]']

I'm not certain, but I believe you would need
to change the order to  'testsync[][2]' ... this
looks like an empty class then one with a single 2
in it, but it's not.  Yours would look like a single
 [ in a class, then a 2 and then... syntax error or
something, since you've got a closing ] without a 
matching opening one.

-Peter




More information about the Python-list mailing list