Case-insensitive globbing

Derek Chen-Becker dbecker at cpicorp.com
Thu Jun 3 16:47:31 EDT 2004


Dennis Lee Bieber wrote:
> On 3 Jun 2004 09:59:36 -0700, tkpmep at hotmail.com (Thomas Philips)
> declaimed the following in comp.lang.python:
> 
> 
>>are in mixed case. How can I do a case-insenstive glob that picks up
>>all files that match a string regardless of case? If its any help, I'm
>>running Python 2.3.4 under Windows XP.
>>
> 
> 	Unless XP has made a drastic change in the handling of file
> names, you don't worry about them...
> 
> 
>>>>flist = glob.glob("D*.*")
>>>>flist
> 
> ['desktop.ini', 'Dennis Lee Bieber.asc', 'Doc1.doc', 'DF297.pdf']

You can also make it cross platform by doing this:

flist = glob.glob("[dD]*.*")

Derek



More information about the Python-list mailing list