If you change the
...
except WindowsError:
print "Map file in use by another program."
sys.exit()
...
with
...
except OSError as e:
print(e)
sys.exit()
...
You will see something like this:
[Errno 2] No such file or directory: 'map1.sk'
Because you map file is in Maps
Directory and you are trying to renamte it like it is in your current directory.
This will do the job:
import os, sys
def parse(path="Maps/"):
for f in os.listdir(path):
try:
os.rename(path+f,path+f.replace("txt","sk"))
except OSError as e:
print(e)
sys.exit()
parse()
I used OSError
instead of WindowsError
because WindowsError
is only available for windows user (not sure but seems like its true).