So,
I am working with some code I don't understand. Here is the file:
import sys
import os
def change_ext(directory, old_ext, new_ext):
for f in os.listdir(sys.argv[1]):
base, ext = os.path.splitext(f)
if ext[1:] == sys.argv[2]:
os.rename(f, "%s.%s" % (base, sys.argv[3]))
if __name__ == '__main__':
if len(sys.argv) < 4:
print "usage: %s directory old_ext new_ext" % sys.argv[0]
sys.exit(1)
change_ext(sys.argv[1], sys.argv[2], sys.argv[3])
When I run it through Jython in Command Prompt as follows:
import chext
chext.change_ext(".", "foo", "java")
It gives me the error:
for f in os.listdir(sys.argv[1]):
Index Error: index out of range: 1
How do I fix this?
- WolfShield