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 cas
Riffing off of @Timothy C. Quinn's answer, this modification allows the use of wildcards anywhere in the path. This is admittedly only case insensitive for the glob_pat argument.
import re
import os
import fnmatch
import glob
def find_files(path: str, glob_pat: str, ignore_case: bool = False):
rule = re.compile(fnmatch.translate(glob_pat), re.IGNORECASE) if ignore_case \
else re.compile(fnmatch.translate(glob_pat))
return [n for n in glob.glob(os.path.join(path, '*')) if rule.match(n)]