Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python - case-insensitive glob
# snippet is placed into public domain by
# anatoly techtonik <>
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')
Copy link

abaybektursun commented Aug 17, 2016

Thanks! This will save some time

Copy link

jnario commented Aug 5, 2017

Very handy, thank you.

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