Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@techtonik
Created June 2, 2013 20:23
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save techtonik/5694830 to your computer and use it in GitHub Desktop.
Save techtonik/5694830 to your computer and use it in GitHub Desktop.
Python - case-insensitive glob
# snippet is placed into public domain by
# anatoly techtonik <techtonik@gmail.com>
# http://stackoverflow.com/questions/8151300/ignore-case-in-glob-on-linux
import fnmatch
import os
import re
def findfiles(which, where='.'):
'''Returns list of filenames from `where` path matched by 'which'
shell pattern. Matching is case-insensitive.'''
# TODO: recursive param with walk() filtering
rule = re.compile(fnmatch.translate(which), re.IGNORECASE)
return [name for name in os.listdir(where) if rule.match(name)]
# findfiles('*.ogg')
@abaybektursun
Copy link

Thanks! This will save some time

@jnario
Copy link

jnario commented Aug 5, 2017

Very handy, thank you.

@hamidallaoui
Copy link

Thanks a lot, it is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment