I need to rename (and edit) files inside a zip file. What I'm doing so far for renaming is:
subprocess.call(["unzip", zipfile, f])
subprocess.call(["zip", "--delete", zipfile, f])
subprocess.call(["mv", f, f_new])
subprocess.call(["zip", "-qq", "-y", "--move", zipfile, f_new])
This clutters the working directory and generally seems like bad coding. Ideally I would have some way to do this inside python and preferably entirely in memory. I have looked at the zipfile
module, however that doesn't seem very intuitive or well documented. It also seems to be missing some basic operations like removing files (Delete file from zipfile with the ZipFile Module). Also appending a file using zipfile
corrupted my archive (I guess it uses its own compression).
Is there a more reasonable way of renaming/deleting/adding/editing zipped files than system calls?
Creating a new zip file from scratch and recompressing everything seems like an even worse option than system calls.