import glob import re files = glob.glob('templates/*/detail.html') + ['templates/detail.html'] for filepath in files: with open(filepath, 'r') as f: content = f.read() # remove literal backslashes before single quotes content = content.replace(r"\'", "'") # remove literal backslashes before double quotes if any content = content.replace(r'\"', '"') with open(filepath, 'w') as f: f.write(content)