Skip to content

Instantly share code, notes, and snippets.

@DevEarley
Created January 26, 2020 01:59
Show Gist options
  • Save DevEarley/ff3b3c327230ea47c46b0270184a9ecf to your computer and use it in GitHub Desktop.
Save DevEarley/ff3b3c327230ea47c46b0270184a9ecf to your computer and use it in GitHub Desktop.
Fix all files in a folder with python
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