Reputation: 3382
I have a zipped file.
Inside of it I have a.tvx
file - which I want to rename to .xml
.
So I tried the following: (of course, I imported all the relevant modules).
with zipfile.ZipFile(file_name) as z:
for filename in z.namelist():
if not os.path.isdir(filename):
os.rename(filename,filename.replace("tvx","xml"))
and the error I got was:
WindowsError: [Error 2] The system cannot find the file specified
I thought that maybe the error was because the filename is not in absolute path,
so I tried also this:
with zipfile.ZipFile(complete_name) as z:
for filename in z.namelist():
if not os.path.isdir(filename):
filename=os.path.abspath(filename) #making filename absolute path
os.rename(filename,filename.replace("tvx","xml"))
but still, the same error.
Upvotes: 0
Views: 2369
Reputation: 3502
You can't rename file within the zip file, So you should extract, rename and rezip the file.
Upvotes: 1