directory - How to skip .hg / .git / .svn directories while recursing tree in python -


i have python script have been piecing (one of first python forays).

the script recurses folder looking xcode project files; script works fine, adapt skip .svn (or .hg or .git) folders isn't trying modify source repositories.

here script recursive search

for root, dirnames, files in os.walk('.'):     files = [f f in files if re.search("project\.pbxproj", f)]     f in files:         filename = os.path.join(root, f)         print "adjusting basesdk %s" % (filename)         ... 

how can exclude repository sub-trees?

as s.lott says in comment, mentioned in documentation os.walk. following should work fine:

for root, dirs, files in os.walk("."):     if ".hg" in dirs:         dirs.remove(".hg")     f in files:         print os.path.join(root, f) 

Comments