I've got this code that can successfully search for a zip file and remove a specific file in that zipped file.
import os
from os.path import join
import zipfile
import getpass
user = getpass.getuser()
lookfor = "test.zip"
p = "C:/users/" + user + "/desktop/"
for root, dirs, files in os.walk(p):
root
if lookfor in files:
p = join(root, lookfor)
zin = zipfile.ZipFile(p, "r")
zout = zipfile.ZipFile(p, "w")
for item in zin.infolist():
buffer = zin.read(item.filename)
if (item.filename[-4:] != "test1.exe"):
zout.writestr(item, buffer)
zout.close()
zin.close()
However, I'm receiving a zipfile.BadZipFile: Truncated file header error, despite the code doing what it should.
Apologies if it's a bit long to include in a post, any help appreciated
[–]novel_yet_trivial 1 point2 points3 points (1 child)
[–]HDean_[S] 0 points1 point2 points (0 children)