G
G
GokenTanmay2020-08-25 11:18:09
Python
GokenTanmay, 2020-08-25 11:18:09

Creating a zip in Python with relative paths?

Good afternoon,
I archive a directory in python with the following code:

def zipdir(path, ziph):
    for root, dirs, files in os.walk(path):
        for file in files:
            ziph.write(os.path.join(root,file))


zipf = zipfile.ZipFile('field/test17.zip', 'w', zipfile.ZIP_LZMA)

zipdir('S:\Folder1\Folder2', zipf)
zipf.close()


Accordingly, files are placed in the archive along the paths starting from the root folder Folder1\Folder2\{path to the file}. How can I make the archive contain files with relative paths simply in the form {path to the file}?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MechanicZelenyy, 2020-08-25
@GokenTanmay

Put files there not using an absolute path, but using a relative one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question