Python standard-library module provides tools to create, read, write, append, and list a ZIP file.
Questions tagged [python-zipfile]
404 questions
4
votes
2 answers
Zipfile in Python file permission
i used zipfile lib to extract file from zip and now after unzip the directory i found the permission of my file has been corrupted ,
import zipfile
fh = open('sample.zip', 'rb')
z = zipfile.ZipFile(fh)
print z.namelist()
for name in z.namelist():
…

Rome
- 563
- 1
- 9
- 25
4
votes
1 answer
Python - Compress all files in a directory using zipfile module
I'm trying to compress all files in a folder (the folder does not have any subdirs) using python zipfile module but can't seem to get the desired output.
I have folderA sitting under F:\Projects\ProjectA\Folders\folderA and my script under…

Riz_K
- 71
- 4
4
votes
1 answer
Python Zipfile extractall IOError on Windows when extracting files from long paths
I'm running python zipfile extractall, its extracting to a path which is longer than 255 characters. Running this on windows 7 64bit.
I'm getting to following error [Errno 2] No such file or directory: u'
Any ideas ?
Its a network folder i want to…

Atti
- 380
- 4
- 21
4
votes
1 answer
zipfile in Python produces not quite normal ZIP files
In my project set of files are created and packed to ZIP archive to be used at Android mobile phone. Android application is opening such ZIP files for reading initial data and then store results of its work to the same ZIPs. I have no access to…

VolAnd
- 6,367
- 3
- 25
- 43
4
votes
3 answers
Use numpy.load on file within zipfile
I have a zipfile which contains many npy files (file1.npy, file2.npy, file3.npy, ...). I would like to load them individually without extracting the zipfile on a filesystem. I have tried many things but I can't figure it out.
My guess was:
import…

Sigmun
- 1,002
- 2
- 12
- 23
4
votes
2 answers
Read ZipFile from URL into StringIO and parse with panda.read_csv
I'm trying to read ZipFile data from a URL and via StringIO parse the data inside the ZipFile as csv using pandas.read_csv
r = req.get("http://seanlahman.com/files/database/lahman-csv_2014-02-14.zip").content
file = ZipFile(StringIO(r))
salaries_csv…

Winston
- 63
- 1
- 6
4
votes
1 answer
How to check if entry is file or folder using Python's standard library zipfile?
I have a zip file and I need to check if a file is a folder or a file without extracting them. I could check it using file_size property of infolist if it is 0 but this is the same for a file with 0 size. So it is not useful.
I looked on the ZIP…

Eduard Florinescu
- 16,747
- 28
- 113
- 179
4
votes
2 answers
Python's zipfile module cannot update entries
I would like to update an entry in a zip file using pythons zipfile module.
My problem is that this generates a new entry.
Please assume I have this code:
from zipfile import ZipFile,ZIP_DEFLATED
with ZipFile("myfile.zip","w") as z:
…

dnagy
- 73
- 6
3
votes
1 answer
how to fast read all excel files inside zip archive and perform operation without taking so much time?
starting the loop to read from two different zip archive 1st excel file and perform some processing to specific row
with ZipFile(Project_path) as zip_file_pro , ZipFile(Reference_path) as zip_file_ref:
for fn_pro,(member_pro , member_ref) in…

armhels
- 41
- 3
3
votes
2 answers
Python ZipFile Slow for big files, Need Alternatives
I am using ZipFile in python to unzip a 6GB file. But it seems to be taking over 3hours to do so.
I need to find a better alternative to fit within 20mins. Below is the code i have been working with which works perfectly fine but is very…

KJoseph
- 53
- 5
3
votes
1 answer
File permissions lost after unzipping with zipfile
I have extracted a zip file (hisat2-2.2.0-Linux_x86_64.zip from https://cloud.biohpc.swmed.edu/index.php/s/hisat2-220-Linux_x86_64/download) in Ubuntu (by right-clicking the file and choose extract here) and this gives me the following file…

justinian482
- 845
- 2
- 10
- 18
3
votes
0 answers
Zipfile can't open a file-like object streaming in request.raw
When I want to decompression a zipfile from internet, there is a error like zipfile.badzipfile: file is not a zip file.
here is my code:
response = requests.get('www.example.com/somefile.zip', stream=True)
response.raw.decode_content = True
with…

neo zoro
- 31
- 2
3
votes
1 answer
Python Zipfile module is throwing errors
I'm trying to get a python Zip module to compress data.
But all it's doing is throwing an error:
with ZipFile(O_file7,mode='w',compression=ZipFile.ZIP_DEFLATED,compressionlevel=9) as file:
AttributeError: type object 'ZipFile' has no attribute…

C0ppert0p
- 634
- 2
- 7
- 23
3
votes
0 answers
Read files with ZipFile using multiprocessing
I'm trying to read raw data from a zipfile. The structure of that file is:
zipfile
data
Spectral0.data
Spectral1.data
Spectral[...].data
Spectral300.data
Header
The goal is to read all Spectral[...].data into an 2D numpy array (whereas…

TMC
- 75
- 10
3
votes
1 answer
Zipfile lib weird behaviour with seconds in modified time
Working with zipfile module I found something weird about how it works.
I'm zipping one file, which last modified attr time is: 13:40:31 (HH:MM:SS)
When I zip and unzip the file, its last mod time is 13:40:30 (lost 1 second)
Doing some tests around…

webbi
- 841
- 7
- 14