Python Forum

Full Version: extract certain file from zip but not complete directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have implemented the following code to copy a specific file from zip to a certain target directory.
But this copies entire structure into the target directory. The code is:

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)
My question is how can I copy only AccountService.json file to target directory but not the entire structure.