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
Here is my non-recursive file search for Python with glob like behavior for Python 3.5+
# Eg: find_files('~/Downloads', '*.Xls', ignore_case=True)
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 os.listdir(os.path.expanduser(path)) if rule.match(n)]
Note: This version handles home directory expansion