小编kis*_*ore的帖子

从 zip 中提取某些文件但不完整目录

我已经实现了以下代码,将特定文件从 zip 复制到某个目标目录。

但这会将整个结构复制到目标目录中。代码是:

import os
import zipfile 

zip_filepath='/home/sundeep/Desktop/SCHEMA AUTOMATION/SOURCE/DSP8010_2017.1.zip'
target_dir='/home/sundeep/Desktop/SCHEMA AUTOMATION/SCHEMA'

with zipfile.ZipFile(zip_filepath) as zf:
    dirname = target_dir
    zf.extract('DSP8010_2017.1/json-schema/AccountService.json',path=dirname)
Run Code Online (Sandbox Code Playgroud)

我的问题是如何仅将 AccountService.json 文件复制到目标目录而不是整个结构。实施shutil有可能吗?

python zip directory-structure shutil

3
推荐指数
1
解决办法
6644
查看次数

标签 统计

directory-structure ×1

python ×1

shutil ×1

zip ×1