Created
January 21, 2019 15:52
-
-
Save Bertbk/9eaacd65813311dea1b2b9bee08d87bb to your computer and use it in GitHub Desktop.
Selected to Featured (hugo academic)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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