Skip to content

Instantly share code, notes, and snippets.

@kerolloz
Last active December 24, 2018 22:29
Show Gist options
  • Save kerolloz/e3849990a52455eeafc4f94689742713 to your computer and use it in GitHub Desktop.
Save kerolloz/e3849990a52455eeafc4f94689742713 to your computer and use it in GitHub Desktop.
change all style.css and script.js sources
import os
from os import remove
def replace(file_path, pattern, subst):
# Create temp file
for filename in os.listdir("."):
if os.path.isdir(filename):
os.chdir("./" + filename)
replace(file_path, pattern, subst)
os.chdir("..")
if filename.endswith("index.php"):
with open("./index.php", 'r') as old_file:
with open("./index2.php", 'w') as new_file:
for line in old_file:
new_file.write(line.replace(pattern, subst))
# Remove original file
remove("index.php")
# Move new file
os.rename("index2.php", "index.php")
print("DONE")
if __name__ == '__main__':
old_style = '''<link rel="stylesheet" href="style.css">'''
new_style = '''<link rel="stylesheet" href="/codecourses/styles/style.css">'''
replace("/home/kerollos/frontEnd/", old_style, new_style)
old_style = '''<script src="script.js"></script>'''
new_style = '''<script src="/codecourses/scripts/script.js"></script>'''
replace("/home/kerollos/frontEnd/", old_style, new_style)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment