Namespaces
Variants
Actions
Revision as of 08:58, 18 September 2012 by hamishwillee (Talk | contribs)

Archived:How to create and extract zip archives using PySymbian

Jump to: navigation, search
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.

178 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved