odf opened this issue on Oct 27, 2008 · 13933 posts
odf posted Mon, 28 February 2011 at 7:06 PM Online Now!
@lesbentley: Below is the conversion script in all its glory. I've been keeping it hidden in this thread because it's bloody stupid ("shipment" becomes "swaistment") and overwrites files in place for a whole folder structure recursively. So it's not for the faint of heart, and particularly not for people who keep only one copy of their files. :laugh:
<span style="font-family:'courier new', courier;">#!/usr/bin/env python
import os, os.path
def replace(text):
out = []
for line in text.split("n"):
out.append(line.replace("hip", "waist").
replace("waist2", "hip").
replace("Hip2", "hip"))
return "n".join(out)
def do_path(path):
if os.path.isdir(path):
for entry in os.listdir(path):
do_path(os.path.join(path, entry))
elif not os.path.islink(path):
fp = open(path)
text = fp.read()
fp.close()
if text.find("hip2") >= 0:
print "Converting " + path + "..."
fp = open(path, "w")
fp.write(replace(text))
fp.close()
if __name__ == "__main__":
import tkFileDialog
path = tkFileDialog.askdirectory(title = "Folder to convert")
do_path(path)
print "Done!"
</span>
-- I'm not mad at you, just Westphalian.