简体   繁体   English

Python Zipfile将完整路径写入文件

[英]Python Zipfile writes full path to file

I am making a zipfile in Python 3 like this: 我正在像这样在Python 3中制作一个zipfile:

zf = zipfile.ZipFile("/path/to/zipfile.zip", mode='w')
try:
    zf.write("/path/to/original.file")
finally:
    zf.close()

However, when I unzip it, I get this structure: 但是,当我将其解压缩时,会得到以下结构:

path
└── to
    └── original.file

How can I resolve this? 我该如何解决?

import os
import zipfile
zf = zipfile.ZipFile("/path/to/zipfile.zip", mode='w')
try:
    os.chdir("/path/to/original file folder")
    zf.write("original.file")
finally:
    zf.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM