Created
July 28, 2012 18:56
-
-
Save chrK/3194414 to your computer and use it in GitHub Desktop.
Revisions
-
Christian Müller revised this gist
Jul 28, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import re root = os.getcwd() includes = ['includes', ] # For files only. excludes = ['excludes', ] # For dirs and files. -
Christian Müller created this gist
Jul 28, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ # -*- coding: utf-8 -*- import os import fnmatch import re root = settings.PROJECT_ROOT includes = ['includes', ] # For files only. excludes = ['excludes', ] # For dirs and files. # Transform glob patterns to regular expressions: includes = r'|'.join([fnmatch.translate(x) for x in includes]) excludes = r'|'.join([fnmatch.translate(x) for x in excludes]) or r'$.' for root, dirs, files in os.walk(project_root): # Exclude dirs: dirs[:] = [os.path.join(root, d) for d in dirs] dirs[:] = [d for d in dirs if not re.match(excludes, d)] # Exclude/include files: files = [os.path.join(root, f) for f in files] files = [f for f in files if not re.match(excludes, f)] files = [f for f in files if re.match(includes, f)] for fname in files: (dir_name, file_name) = os.path.split(fname) (file_base_name, file_extension) = os.path.splitext(file_name) print dir_name, file_name