Questions tagged [python-zipfile]

Python standard-library module provides tools to create, read, write, append, and list a ZIP file.

404 questions
17
votes
2 answers

How do I know an item is a directory while looping over zipfile in Python?

Doing something like this: from zipfile import ZipFile #open zip file zipfile = ZipFile('Photo.zip') #iterate zip contents for zipinfo in zipfile.filelist: #do something filepath, filename = path.split(zipinfo.filename) How do I know if…
neurino
  • 11,500
  • 2
  • 40
  • 63
16
votes
1 answer

Python zipfile module: difference between zipfile.ZIP_DEFLATED and zipfile.ZIP_STORED

I have difficulty understanding the difference between zipfile.ZIP_DEFLATED and zipfile.ZIP_STORED compression modes of the zipfile module.
maxim
  • 583
  • 2
  • 5
  • 13
16
votes
4 answers

Opening zipfile of unsupported compression-type silently returns empty filestream, instead of throwing exception

Seem to be knocking my head off a newbie error and I am not a newbie. I have a 1.2G known-good zipfile 'train.zip' containing a 3.5G file 'train.csv'. I open the zipfile and file itself without any exceptions (no LargeZipFile), but the resulting…
smci
  • 32,567
  • 20
  • 113
  • 146
15
votes
4 answers

ZipFile.testzip() returning different results on Python 2 and Python 3

Using the zipfile module to unzip a large data file in Python works correctly on Python 2 but produces the following error on Python 3.6.0: BadZipFile: Bad CRC-32 for file 'myfile.csv' I traced this to error handling code checking the CRC…
Ethan White
  • 495
  • 7
  • 11
15
votes
2 answers

Python using ZIP64 extensions when compressing large files

I have a script that compresses the output files. The problem is that one of the files is over 4Gigs. How would I convert my script to use ZIP64 extensions instead of the standard zip? Here is how I am currently zipping: try: import zlib …
txwylde
  • 151
  • 1
  • 1
  • 4
14
votes
2 answers

Bad magic number error with ZipFile module in Python

I am using Python 2.7 on Windows 7 (64 bit). When I try to unzip a zip file with ZipFile module I get the following error:- Traceback (most recent call last): File "unzip.py", line 8, in z.extract(name) File…
haltTm
  • 534
  • 1
  • 6
  • 25
14
votes
1 answer

Forcing a specific timestamp for files in pythons zipfile

Is it possible to force a specific timestamp for a file when adding it to a zipfile? Something along these lines: with ZipFile('spam.zip', 'w') as myzip: myzip.write('eggs.txt', date_time=(1752, 9, 9, 15, 0, 0)) Can I change the ZipInfo on a…
dantje
  • 1,739
  • 1
  • 13
  • 25
13
votes
2 answers

Unable to unzip a large zip file (3.3GB) in iOS9 using SSZipArchive

As title, I creates the zip file from my Django backend server (hosted on a Ubuntu 14.04.1 LTS) using the python zipfile module: zipfile.ZipFile(dest_path, mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=True) I managed to…
chubao
  • 5,871
  • 6
  • 39
  • 64
13
votes
4 answers

zipfile.write() : relative path of files, reproduced in the zip archive

Using zip file, I indicate files locate within an other folder for example: './data/2003-2007/metropolis/Matrix_0_1_0.csv' My problem is that, when I extract it, the files are found in ./data/2003-2007/metropolis/Matrix_0_1_0.csv, while I would like…
Touki
  • 833
  • 2
  • 9
  • 20
12
votes
2 answers

How to check if a zip file is encrypted using python's standard library zipfile?

I am using python's standard library, zipfile, to test an archive: zf = zipfile.ZipFile(archive_name) if zf.testzip()==None: checksum_OK=True And I am getting this Runtime exception: File "./packaging.py", line 36, in test_wgt if…
Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
11
votes
1 answer

How can I pass a Python StringIO() object to a ZipFile(), or is it not supported?

I have a StringIO() file-like object, and I am trying to write it to a ZipFile(), but I get this TypeError: coercing to Unicode: need string or buffer, cStringIO.StringI found Here is a sample of the code I am using: file_like = StringIO() archive…
Brian
  • 1,703
  • 3
  • 17
  • 23
11
votes
5 answers

archiving symlinks with python zipfile

I have a script that creates zip files of dirs containing symlinks. I was surprised to find that the zipfiles have zipped the targets of the links as opposed to the links themselves, which is what I wanted and expected. Anyone know how to get…
Larry Martell
  • 3,526
  • 6
  • 40
  • 76
11
votes
3 answers

why can't python unzip a password protected zip file created by winrar using the zip method?

I have searched the web high and low but still couldn't find a solution for the above problem. Does anyone out there know why and if so how it can be done? psw="dg" ZipFile.extractall("data.zip", None, psw) The error that I've got: TypeError:…
wookie
  • 329
  • 1
  • 5
  • 13
10
votes
4 answers

Is python zipfile thread-safe?

In a django project, I need to generate some pdf files for objects in db. Since each file takes a few seconds to generate, I use celery to run tasks asynchronously. Problem is, I need to add each file to a zip archive. I was planning to use the…
Thibault J
  • 4,336
  • 33
  • 44
10
votes
3 answers

python: zipfile.ZipFile No such file or directory

There is folder path: P:\\2018\\Archive\\ There are many zipfiles I want to create programmatically, but am starting with test. I will name this test zip file "CO_007_II.zip" and will attempt to create in above location: import zipfile as zp with…
geoJshaun
  • 637
  • 2
  • 11
  • 32
1
2
3
26 27