There is something I haven’t understood on how to use shutil.make_archive
.
Example:
While at /path/to/
, I do
import shutil
shutil.make_archive(base_name='text.txt', format='zip', base_dir='/path/to/text.txt')
The result is a file text.txt.zip
located at /path/to/text.txt.zip
. Fine.
In the archive, the entire path /path/to/text.txt
has been replicated.
Question 1: How should shutil.make_archive
be used to only have text.txt
inside the zip file?
Note: Instead of just a file text.txt
I might also want to archive a directory, but I also do not want the entire path to it inside the zip file.
In the documentation it says
Changed in version 3.10.6: This function is now made thread-safe during creation of standard
.zip
and tar archives.
Question 2: What is a not “standard .zip
[…] archive”? Am I, in the example above, in a standard case?
I get the same effect with
import shutil
shutil.make_archive(base_name='text.txt', format='zip', base_dir='/path/to/text.txt', root_dir='/path/to')
In this example in the documentation they get the directory tree in the archive, but starting from root_dir
.