Questions tagged [python-zipfile]

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

404 questions
2
votes
1 answer

Cannot open file in subdirectory with ZipFile

For whatever reason i cannot open or access the file in this subdirectory. I need to be able to open and read files within subdirectories of a zipped folder. Here is my code. import zipfile import os for root, dirs, files in os.walk('Z:\\STAR'): …
Syllogism
  • 145
  • 1
  • 1
  • 10
2
votes
1 answer

Create a ZipFile in memory and attach it to an email

I'm trying to modify an existing python script to convert an in-memory CSV into an (also in memory) zip archive and send it as an attachment to an email. I've had success attaching an in memory CSV file (via a MIMEText object) but am having trouble…
daniel9x
  • 755
  • 2
  • 11
  • 28
2
votes
0 answers

Python: How to efficiently open and read a zipfile from multiple processes

I'm trying to open the same .zip file from multiple processes using zipfile and multiprocessing. When I open the .zip file using the with zipfile.ZipFile(self.path, 'r') as archive: syntax, the code across multiple processes works without issues,…
malem
  • 51
  • 3
2
votes
1 answer

Why does Python zipfile not give the same output .zip file size as command-line zip?

Here is the size of the file generated by zip: $ seq 10000 > 1.txt $ zip 1 1.txt adding: 1.txt (deflated 54%) $ ls -og 1.zip -rw-r--r-- 1 22762 Aug 29 10:04 1.zip Here is an equivalent python script: import zipfile z =…
user1424739
  • 11,937
  • 17
  • 63
  • 152
2
votes
1 answer

ZipFile get creation date

I would like to get the creation date of a file inside zipped folder. I know that without zip, this can be achieved with using os.path.getctime() function and last modified date of a file inside zipped folder can be extracted with ZipInfo.date_time.…
Darren Christopher
  • 3,893
  • 4
  • 20
  • 37
2
votes
1 answer

Reading ARFF from ZIP with zipfile and scipy.io.arff

I want to process quite big ARFF files in scikit-learn. The files are in a zip archive and I do not want to unpack the archive to a folder before processing. Hence, I use the zipfile module of Python 3.6: from zipfile import ZipFile from…
2
votes
2 answers

Create zipfile at local and write files from s3

I am creating a zipfile on my local machine and would like to write files from s3. So far I'm unable to do it. Here's what I have in the mean time. import os import zipfile from fs import open_fs fs =…
alvirbismonte
  • 349
  • 2
  • 7
  • 26
2
votes
1 answer

Python - load an in-memory ZipFile object as bytes

I have a script which creates a closed in-memory ZipFile object that I need to post as a bytestring (using requests); how do I do that? I have tried opening the file, which fails with "TypeError: expected str, bytes or os.PathLike object, not…
Tim Achee
  • 37
  • 1
  • 3
2
votes
2 answers

Python zipfile does not unzip folders for windows zip archive

I have a zip file which was created on Windows machine using this tool System.IO.Compression.ZipFile (this zip archive contains many files and folders). I have a python code that runs on Linux machine (raspberry pi to be exact) which has to unzip…
Mykhailo Seniutovych
  • 3,527
  • 4
  • 28
  • 50
2
votes
2 answers

File update : multiple versions stored inside the ZIP archive

Let's say we have a test.zip file and we update a file: zfh = zipfile.ZipFile("test.zip", mode = "a") zfh.write("/home/msala/test.txt") zfh.close() Repeating a few times this "update", using the builtin method printdir() I see in the archive there…
Massimo
  • 3,171
  • 3
  • 28
  • 41
2
votes
1 answer

zipfile module giving unreliable results

I made a dictionary attack on encrypted zip files, using the zipfile library. When I started using BIG dictionaries sometimes I got false positive results, i.e. password could be "wool" and "12630" was considered correct. In that case the decrypted…
Erethon
  • 123
  • 1
  • 9
2
votes
1 answer

how to add dynamically generated pdf file to zipfile Python?

z = zipfile.ZipFile("zipfile.zip", "w") z.write(filename) It takes string as an argument that is actually path of that file to be add to the zip. But I want to add dynamically generated file.
2
votes
1 answer

Read separately zipped csv file (.zip .z01 etc) over Python zipfile library

How could we read csv file which is zipped into multiple files? Due to the 4 GB limit of FAT storage format, I have complied csv file into multiple zip files like test.zip and test.z01. I found the library zipfile which can read csv file in the…
JonghoKim
  • 1,965
  • 7
  • 21
  • 44
2
votes
2 answers

Extracting large files with zipfile

I'm trying to extract a zip file of 1.23 GB with zipFile library. But it gives the following error: compression type 9 (deflate64) Here's my code: zip_ref = zipfile.ZipFile(filepath, 'r') zip_ref.extractall(newPath) It gives error while trying to…
Tahreem Iqbal
  • 985
  • 6
  • 17
  • 43
2
votes
2 answers

How can i extract files using custom names with zipfile module from python?

I want to add suffix to names of my files, for example uuid. How can i extract files using zipfile and pass custom names?
SuitUp
  • 3,112
  • 5
  • 28
  • 41