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

How do I know that a .npz file was compressed or not?

Given a .npz file from np.savez or np.savez_compressed, when it got loaded by np.load, is there any way to check whether the file was compressed or not? I tried to look though docs and GitHub. It didn't tell me anything but how the file is…
ACitronella
  • 43
  • 1
  • 4
2
votes
0 answers

What is the problem with my resizing .img files?

Please note that I'm doing my first programming project and I'm inexperienced. It's a simple project, but I'm having trouble with one problem: the result is always the same image. I've checked the file names and they are correct, but the picture is…
2
votes
3 answers

How to zip files that ends with certain extension

I want to get all files in a directory (I reached it after doing several for loops - hence fourth.path) that ends with .npy or with csv and then zip those files. My code is running putting one file only in the zip file. What am I doing wrong? I…
2
votes
1 answer

Python - Creating Zip in stream that exceeds RAM

I'm trying to create a zip file on the fly of a directory and return it to the user over a Flask App. The below works great for smaller directories but I'd also like to achieve this with large directories full of images (>20GB). def return_zip(): …
James Watson
  • 35
  • 1
  • 4
2
votes
1 answer

How to pack several DataFrames into one file using zipfile

I have a few DataFrames that I need to zip to one file. This is my code: df_list = [ojcowskieDF,mateczneDF] with zipfile.ZipFile('final.zip', 'w') as zipF: for file in df_list: zipF.write(file, compress_type=zipfile.ZIP_DEFLATED) But I…
maciej.o
  • 127
  • 1
  • 13
2
votes
2 answers

How to load a zip file with pyscript and save into the virtual file system

I am trying to load a zip file and save it in the virtual file system for further processing with pyscript. In this example, I aim to open it and list its content. As far as I got: See the self standing html code below, adapted from tutorials (with…
2
votes
3 answers

Python zipfile.ZipFile zips a corrupt file

I have a Django view which users can call to zip files at my local server. It uses zipfile.ZipFile to compresses multiple files into a single zip as follows: with ZipFile(my_dir + 'folder.zip', 'w') as zipObj: zipObj.write(my_dir +…
sshussain270
  • 1,785
  • 4
  • 25
  • 49
2
votes
1 answer

ValueError: write() requires mode 'w', 'x', or 'a' in Python zipfile

I am trying to open a specific file in the archive and then write some content to it. I am using the zipfile.open() function to get access to the file: import zipfile my_zip = zipfile.ZipFile('D:\\files\\acrhive.zip') with…
Real Noob
  • 1,369
  • 2
  • 15
  • 29
2
votes
1 answer

Zipfile python module bytesize difference

I'm using zipfile module for python to extract a zipfile I retrieved from the internet using urllib.urlretrieve() the files in the zip file are patch files created by bsdiff, however when I let python extract the zip file and try to use bspatch it…
M0rph3v5
  • 945
  • 1
  • 11
  • 23
2
votes
2 answers

ZipFile: Check for correct Password

I have this code to unzip a zip file that is encrypted with a password: import zipfile def main(pswd): file_name = 'somefile.zip' with zipfile.ZipFile(file_name) as file: return file.extractall(pwd = bytes(pswd,…
Kanexxy
  • 17
  • 6
2
votes
1 answer

How to avoid subfolders creation while zipping files?

I am trying to zip the files from the list localpath_list in to one zip file `reports.zip. It works as expected, but when I extract the reports.zip file, there are folders created inside it. i.e all the .xls files are under files/sample/. what I…
massu1000
  • 209
  • 2
  • 10
2
votes
1 answer

How to allow extraction of all files even the ones with same name?

I'm struggling with unzip process with this code: I have two separated .zip files and each has the same file name and file type, but when I execute this code only appears one file extracted, instead of two. This is the result: Code: import os,…
2
votes
0 answers

How to unzip specific subfolders of a zip archive with Python zipfile

I want to unzip particular subfolders from a list of zip archives using the zipfile module. Paths to archives are stored in a csv file with concatenated subfolders, like…
llkrht
  • 21
  • 3
2
votes
2 answers

Python Zipfile compression method is not supported

The times when this worked were when I used ZIPCrypto compression. It's with AES-256 that it fails. How to get around this please? I previously had success using the following Python code to open a password protected .zip file created with…
Robin Andrews
  • 3,514
  • 11
  • 43
  • 111
2
votes
2 answers

PermissionError when attempting to open directory with zipfile and pathlib modules

I'm trying to create a zip file using pathlib, but it's giving me a permission error. Look at the code: from pathlib import Path from zipfile import * import os from datetime import datetime time = str(datetime.now()) day = int(time.split('…