Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unzip z01, z02, zip file in python

Tags:

python

zip

Currently, I have a big zip file splited into 3 file test.zip, test.z01, test.zip02

I use zipfile library in python to extract these file, but encounter the

error: "BadZipFile: Bad magic number for file header"

with zipfile.ZipFile("test.zip","r") as file:
    file.extractall(folder_path)

Anyone know how to extract these file with Python.

like image 849
Hoang Huy Avatar asked Jun 01 '26 12:06

Hoang Huy


1 Answers

Calling command line interfare of 7zip/winrar in python should solve this problems

import subprocess
unzip_command = '"C:\\Program Files\\7-Zip\\7z.exe"' +  ' e ' + '"' + folder_path + '"'
subprocess.run(unzip_command, shell = True, cwd = folder_path)

The code above will extract all file in folder_path folder and store the file in this

like image 187
Hoang Huy Avatar answered Jun 03 '26 01:06

Hoang Huy