Skip to content

Instantly share code, notes, and snippets.

@jorgeas80
Forked from techtonik/findfiles.py
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeas80/9231178 to your computer and use it in GitHub Desktop.
Save jorgeas80/9231178 to your computer and use it in GitHub Desktop.
List the full path of all files on a directory filtered by a shell pattern
# Adapted from snippet 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 [os.path.abspath(os.path.join(root, file)) for root, dirs, files in os.walk(where) for file in files if rule.match(file)]
# findfiles('*.ogg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment