Skip to content

Instantly share code, notes, and snippets.

@kzahel kzahel/

Created Sep 4, 2016
What would you like to do?
replace recursive text exclude .git directory
import os, fnmatch
def findReplace(directory, find, replace, filePattern):
for path, dirs, files in os.walk(os.path.abspath(directory), topdown=True):
dirs[:] = [d for d in dirs if d not in '.git']
for filename in fnmatch.filter(files, filePattern):
filepath = os.path.join(path, filename)
with open(filepath) as f:
s =
s = s.replace(find, replace)
with open(filepath, "w") as f:
#findReplace("www", "", "", "*")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.