Created
January 26, 2020 01:59
-
-
Save DevEarley/ff3b3c327230ea47c46b0270184a9ecf to your computer and use it in GitHub Desktop.
Fix all files in a folder with python
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
import os | |
folder = 'D:\Projects\python\poems_need_fixing\\' | |
for filename in os.listdir(folder): | |
full_filename = folder+filename | |
print " START " + filename | |
r = open(full_filename,'r') | |
lines = r.readlines() | |
open(full_filename, "w").close() | |
newLines = [line.replace('```','\r```') for line in lines] | |
f = open(full_filename,'r+') | |
f.truncate(0) | |
f.writelines(newLines) | |
f.close() | |
print " FINISHED " + filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment