Created
March 25, 2014 13:07
-
-
Save fredrikaverpil/9761449 to your computer and use it in GitHub Desktop.
Walk folder and search and replace in files #python
This file contains 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 | |
startDirectory = "c:/temp/" | |
searchString = "maya2012" | |
replacement = """multiline | |
string""" | |
for dname, dirs, files in os.walk(startDirectory): | |
for fname in files: | |
if ".ma" in fname: | |
fpath = os.path.join(dname, fname) | |
print "Reading " + fpath | |
with open(fpath) as f: | |
s = f.read() | |
s = s.replace(searchString, replacement) | |
with open(fpath, "w") as f: | |
f.write(s) | |
print "Wrote " + fpath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment