简体   繁体   中英

Python Zipfile writes full path to file

I am making a zipfile in Python 3 like this:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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