#!/usr/bin/python
import sys, os, re

with open("setting.ini") as f:
    path = f.readline().rstrip("\r\n")
    regex = f.readline().rstrip("\r\n")
    repl = f.readline().rstrip("\r\n")

if os.path.isdir(path):
    for dirpath, dirnames, filenames in os.walk(path):
        for name in filenames:
            path = os.path.join(dirpath, name)
            contents = open(path).read()
            if re.search(regex, contents):
                open(path, "w").write(re.sub(regex, repl, contents))
else:
    sys.stderr.write("Error\n")