You can download this code by clicking the button below.
This code is now available for download.
This function takes the path of a ZIP file and the target extraction directory, and extracts the ZIP file to the target directory.
Technology Stack : zipfile
Code Type : Unzip ZIP file
Code Difficulty : Intermediate
def zipfile_extract(file_path, extract_to_dir):
"""
解压ZIP文件到指定目录。
"""
import zipfile
try:
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(extract_to_dir)
return True
except zipfile.BadZipFile:
return False