[Tutor] removing file from zip archive.

Keo Sophon keosophon at khmeros.info
Wed Mar 29 10:43:48 CEST 2006


On Wednesday 29 March 2006 15:38, Tim Golden wrote:
> | How can we remove one file inside of a zip archive?
> |
> | I'm using this method:
> |
> | 	import zipfile
> |
> | 	ziparchive = zipfile.ZipFile('test.odt', 'r')
> | 	xmldata = ziparchive.read('content.xml')
> | 	ziparchive.close
>
> (Warning: not my area of expertise, but...)
>
> Your example *reads* one file from within a zip
> archive, and is a perfectly good way of doing it
> (indeed pretty much the only way of doing it).
> Do I take it you want to end up with the same
> archive but without that file?
>
> If so, I don't believe it's possible as such.
> What you'd have to do -- and this is almost
> certainly what any front-end tool will do for
> you behind-the-scenes -- is to copy the contents
> of the archive to a temporary file omitting the
> file(s) in question, and then to rename the
> temporary file over the original.
>
> TJG
>

Thank you.

Sophon


More information about the Tutor mailing list