Questions tagged [python-zipfile]

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

404 questions
1
vote
0 answers

Force python to read file with arbitrary extension as .txt file from archive using zipfile

Thank you snakecharmerb. This was my solution. Thank you for helping an io amateur. Occasionally throws errors, which doesn't happen if I decompress then search, but now I'm off and running. I've got a few TB of files sitting in .zip files with a…
Matt Reed
  • 19
  • 3
1
vote
1 answer

How to avoid file content repetition zipfile

I need to compress multiple xml files and I achieved this with lxml, zipfile and a for loop. My problem is that every time I re run my function the content of the compressed files are repeating (being appended in the end) and getting longer. I…
Simon Capriles
  • 143
  • 2
  • 21
1
vote
1 answer

Python ZipFile Created In-Memory Not Compressing as Expected

I am trying to use Python to create a ZipFile object in-memory, and write a single file, also created in-memory, into the ZipFile object, and then upload the file to Google Cloud Storage. My file is not actually getting compressed. Any idea what I…
1
vote
2 answers

How to close zip file, from zipfile?

When I try to unzip a file, and delete the old file, it says that it's still running, so I used the close function, but it doesn't close it. Here is my code: import zipfile import os onlineLatest = "testFile" myzip =…
1
vote
1 answer

How to get the pictures in group from excel files

I have tried to extract pictures from excel, but after grouping the text or lines inserted in Excel with pictures, the pictures after the group cannot be completely extracted when extracting the pictures. What should I do? This is the code I…
Peter
  • 100
  • 10
1
vote
1 answer

How do I brute force a password protected zip file with a three digit password?

The problem is stated here: Sample Alien Zip file found at /tmp/alien-zip-2092.zip is password protected. We have worked out they are using a numerical three digit code. Brute force the Zip file to extract to /tmp Note: The script can timeout if…
DuckHunt
  • 68
  • 1
  • 11
1
vote
0 answers

Read Zip file from an URL and download specific .csv file in python

The following reproducible code is giving me: BadZipFile("File is not a zip file") error. I don't know how to fix it. import pandas as pd from io import StringIO, BytesIO, TextIOWrapper from zipfile import ZipFile import urllib url =…
Georg_Z
  • 15
  • 3
1
vote
0 answers

ZipFile.extractall removes files from zip but doesn't save them anywhere

I'm writing a function which takes a set of files then either: saves the files to a zip file if they are present. or extract files from said zip file if they are not present. Saving the files to a zip is working fine, but when it comes to…
MaccyF
  • 11
  • 1
1
vote
0 answers

Zipfile.extractall() throwing Errno 22 after relocation to shared drive on 4 iteration. Script known good

I'm extracting geodatabase replicas downloaded from ArcGIS Online from zip files. The script iterates across a json to drive the process. When this was in my C drive it executed smoothly. When I moved it to a network drive it failed on the 4th…
Crash
  • 15
  • 4
1
vote
1 answer

How to password protect an object of type ZipFile?

I am trying to send a password protected zip file as a base64 string. data = BytesIO() zip = zipfile.ZipFile(data, 'w') zip.writestr('test.csv', 'Hello, World') zip.setpassword(b'1234') zip.close() b64zip =…
Matthew
  • 1,461
  • 3
  • 23
  • 49
1
vote
1 answer

How do I extract and process all the files in a zipfile?

I want to extract and process all the files in a zipped file? import re import zipfile import pathlib import pandas as pd # Download mHealth dataset def parse(zip_file): # Extract all the files in output directory with…
melil
  • 81
  • 8
1
vote
1 answer

Is there a way to change the name of the files extracted using zipfile in Python?

I'm trying to extract a csv file from a zip folder and choose its name as it is saved in the new directory. This code is working well to extract the file: import zipfile with zipfile.ZipFile(f'C:\\Users\\user\\Downloads\\{nombre_solar_zip}', 'r') as…
Acedo
  • 13
  • 2
1
vote
1 answer

How to obtain path from ZipFile objects that could be passed into OpenCV?

I would like to pass the image file into OpenCV to create a NumPy array without unzipping it. My code looks like this: zip_file = r'D:\Folder\small_img.zip' with zipfile.ZipFile(zip_file) as zip: for info in zip.infolist(): …
C.Ann.Sng
  • 63
  • 4
1
vote
1 answer

How to zip files without including the folder they are in?

I am trying to use zipfile to zip several files together into a single .zip file. The files I need to zip are not in the root folder from which the python script runs, so i have to specify the path when adding a file to the zip. The problem is that…
1
vote
1 answer

How to change directory with zipfile?

I can see general questions about zipfile, not sure I'm missing something about my specific question (but I feel it's an obvious question, so sorry if it's out there). I have a zip file with multiple directories, I want to cd within the zipfile, and…
Slowat_Kela
  • 1,377
  • 2
  • 22
  • 60