Python, how to implement something like .gitignore behavior
I need to list all files in the current directory (.) (including all sub directories), and exclude some files as how .gitignore works ( http://git-scm.com/docs/gitignore ) With fnmatch ( https://docs.python.org/2/library/fnmatch.html ) I will be able to "filter" files using a pattern ignore_files = ['*.jpg', 'foo/', 'bar/hello*'] matches = [] for root, dirnames, filenames in os.walk('.'): for filename in fnmatch.filter(filenames, '*'): matches.append(os.path.join(root, filename)) how can I "filter" and get all files which doesn't match with one or more element of my "ignore_files"? Thanks! You