You can download this code by clicking the button below.
This code is now available for download.
This function accepts the path to a zip file and the path to the target directory for extraction, and then uses the built-in zipfile library to extract the file.
Technology Stack : zipfile
Code Type : File operation
Code Difficulty : Intermediate
def zipfile_extract(file_path, extract_to_dir):
"""
解压一个zip文件到指定的目录。
:param file_path: str, zip文件的路径。
:param extract_to_dir: str, 解压目标目录的路径。
"""
import zipfile
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(extract_to_dir)