Created
September 4, 2016 01:32
-
-
Save kzahel/f160f82a2e8fbb4ed28c109470a79501 to your computer and use it in GitHub Desktop.
replace recursive text exclude .git directory
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 characters
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 = f.read() | |
s = s.replace(find, replace) | |
with open(filepath, "w") as f: | |
f.write(s) | |
#findReplace("www", "https://activities.learn-the-web.algonquindesign.ca", "http://activities.learn-the-web.tlmworks.org", "*") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment