Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shutil.make_archive not zipping to correct destination

As per the code below I am having issues with the zipping a directory using the python 3 shutil.make_archive function. The .testdir will be zipped but it is being zipped in /home/pi, instead of /home/pi/Backups.

zip_loc = '/home/pi/.testdir'
zip_dest = '/home/pi/Backups/'
shutil.make_archive(zip_loc, 'zip', zip_dest)

Could anyone explain what I am doing wrong?

like image 351
somerandomguy95 Avatar asked Oct 14 '17 06:10

somerandomguy95


1 Answers

Reading the docs here I came up with:

zip_loc = '/home/pi/.testdir'
zip_dest = '/home/pi/Backups/'
shutil.make_archive(base_dir=zip_loc, root_dir=zip_loc, format='zip', base_name=zip_dest)

From the docs:

base_name is the name of the file to create, including the path, minus any format-specific extension.

 

root_dir is a directory that will be the root directory of the archive; for example, we typically chdir into root_dir before creating the archive.

 

base_dir is the directory where we start archiving from; i.e. base_dir will be the common prefix of all files and directories in the archive.

 

root_dir and base_dir both default to the current directory.

like image 51
Mykola Shchetinin Avatar answered Sep 19 '22 14:09

Mykola Shchetinin