Skip to content

Instantly share code, notes, and snippets.

@Bertbk
Created January 21, 2019 15:52
Show Gist options
  • Select an option

  • Save Bertbk/9eaacd65813311dea1b2b9bee08d87bb to your computer and use it in GitHub Desktop.

Select an option

Save Bertbk/9eaacd65813311dea1b2b9bee08d87bb to your computer and use it in GitHub Desktop.
Selected to Featured (hugo academic)
# Found here
# https://stackoverflow.com/questions/4205854/python-way-to-recursively-find-and-replace-string-in-text-files
import os, fnmatch
def findReplace(directory, find, replace, 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()
s = s.replace(find, replace)
with open(filepath, "w") as f:
f.write(s)
findReplace(".", "Selected", "Featured", "*.toml")
findReplace(".", "selected", "featured", "*.toml")
findReplace("content", "selected", "featured", "*.md")
findReplace("content", "Selected", "Featured", "*.md")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment