Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Replaces all strings in all files with given encoding and extension recursively in all sub directories.
- # Strings to replace are given by .def file, every line should look like before_string:after_string
- import os
- subs_file = 'subs.def'
- encoding = 'utf-8'
- extension = '.vcxproj'
- subs = {}
- f = open(subs_file)
- for line in f.readlines():
- (before, after) = line.split(':')
- after = after.rstrip()
- subs[before] = after
- for root, dirs, files in os.walk('.'):
- for fname in files:
- if not fname.endswith(extension): continue
- path = os.path.join(root, fname)
- print("Processing " + path)
- f = open(path, "rb")
- content_str = f.read().decode(encoding)
- f.close()
- for before in subs: content_str = content_str.replace(before, subs[before])
- f = open(path, "wb")
- f.write(content_str.encode(encoding))
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement