import os, sys
PATH=r"C:\Programme\L2j Server\jscript"
TYPES={'q':'quests','b':'blacksmith','v':'village_master','t':'teleports','c':'custom'}
j=os.path.join
log=open("log.log", "w")
sys.stdout=log
for abbr, full in TYPES.iteritems():
print "\n", full, "\n*************"
path=j(PATH, full)
files=os.listdir(path)
for dir in files:
fulldir=j(path, dir)
if os.path.isdir(fulldir) and dir[0].isdigit():
changed=0
allfiles=os.listdir(fulldir)
for file in allfiles:
fullfile=j(fulldir, file)
if os.path.isfile(fullfile) and (os.path.splitext(file)[1]==".htm" or file=="__init__.py"):
f=open(fullfile, "r")
script=f.read()
f.close()
count=script.count(dir)
if count:
script=script.replace(dir, abbr+dir)
if file=='__init__.py':
changed=1
elif file=="__init__.py":
print "WARNING: %s found %s times in %s" % (dir, count, fullfile)
f=open(fullfile, "w")
f.write(script)
f.close()
if changed:
os.rename(fulldir, j(path, abbr+dir))
print "completed", full