Ignore case in glob() on Linux
Question: I'm writing a script which will have to work on directories which are modified
by hand by Windows and Linux users alike. The Windows users tend to not care
at all about case in assigning filenames.

Is there a way to handle this on the Linux side in Python, i.e. can I get a
case-insensitive, glob-like behaviour?


Answer: You can replace each alphabetic character c with [cC], via

    
    
    import glob
    def insensitive_glob(pattern):
        def either(c):
            return '[%s%s]'%(c.lower(),c.upper()) if c.isalpha() else c
        return glob.glob(''.join(map(either,pattern)))
    

