Archived:How to create and extract zip archives using PySymbian
Article Metadata
Tested with
Devices(s): Nokia N95, Nokia E90
Compatibility
Platform(s): S60 1st Edition, S60 2nd Edition, S60 3rd Edition
Platform Security
Capabilities: )
Article
Keywords: zipfile
Created: bogdan.galiceanu
(02 Jun 2008)
Last edited: hamishwillee
(18 Sep 2012)
Contents |
Overview
This article shows how to create and extract zip archives in Python.
Source code
Creating an archive
import zipfile
#Create a new archive
a = zipfile.ZipFile("C:\\x.zip", 'w')
#Add the file "x.sis" to the archive
a.write("C:\\x.sis")
#Close the archive
a.close()
Appending to an existing archive
import zipfile
#Open an archive
a = zipfile.ZipFile("C:\\x.zip", 'a')
#Add the file "y.sis" to the archive
a.write("C:\\y.sis")
#Close the archive
a.close()
Extracting the contents of an archive
import zipfile
#Open the archive in read mode
a = zipfile.ZipFile("C:\\x.zip", 'r')
#Extract every file from it
for i in a.namelist():
b = open("C:\\"+i, 'wb')
b.write(a.read(i))
b.close()
#Close the archive
a.close()
Postconditions
The operations described above are performed.
Additional information
More information about the zipfile library can be found here.

