Y
Y
Yaroslav Ogloblin2019-02-14 16:07:51
Python
Yaroslav Ogloblin, 2019-02-14 16:07:51

How to add a folder to the archive that is not on the disk?

There is a task to create zip-archives containing a tree of folders with files. But one caveat, these folders are not on the disk, there are only files with different names, and the tree is contained in the database.
I tried to use the standard zipfile, but when I tried to call the write method, I got an error that there is no such folder on the disk.
Please tell me how to solve this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Shatalov, 2019-02-14
@netpastor

And what prevents you from first creating the desired folder tree with files, and then zipping it?

A
Alexander, 2019-02-16
@Survtur

from zipfile import ZipFile

with ZipFile('archive.zip', 'a') as z:
    z.write('some_file.ext', arcname='path/you/want/some_file.ext')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question