Extract files from zip without keeping the structure using python ZipFile?

后端 未结 5 1639
栀梦
栀梦 2020-11-27 16:10

I try to extract all files from .zip containing subfolders in one folder. I want all the files from subfolders extract in only one folder without keeping the original struc

5条回答
  •  独厮守ぢ
    2020-11-27 16:31

    A similar concept to the solution of Gerhard Götz, but adapted for extracting single files instead of the entire zip:

    with ZipFile(zipPath, 'r') as zipObj:
        zipInfo = zipObj.getinfo(path_in_zip))
        zipInfo.filename = os.path.basename(destination)
        zipObj.extract(zipInfo, os.path.dirname(os.path.realpath(destination)))
    

提交回复
热议问题