Skip to content

Instantly share code, notes, and snippets.

@sarathlal-old
Last active March 2, 2016 14:01
Show Gist options
  • Save sarathlal-old/b80cd269d4a78c7f4ab4 to your computer and use it in GitHub Desktop.
Save sarathlal-old/b80cd269d4a78c7f4ab4 to your computer and use it in GitHub Desktop.
import os, fnmatch
def findReplace(directory, filePattern):
for path, dirs, files in os.walk(os.path.abspath(directory)):
for filename in fnmatch.filter(files, filePattern):
filepath = os.path.join(path, filename)
with open(filepath) as f:
s = f.read().splitlines(True)
with open(filepath, "w") as f:
f.write("<?php")
f.writelines(s[1:])
# findReplace("directory", "*file extension")
findReplace("/var/www/project_20", "*.php")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment