I am trying to use shutil.make_archive to zip files.
When I am using :
import shutil
shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test')
I got a zip_file in the zip_file, and the zip_file in the zip_file seems to be a corrupted file. Anyone knows how to deal with it?
However, when I am using :
make_archive(
'zipfile_name',
'zip', # the archive format - or tar, bztar, gztar
root_dir=file_dir, # root for archive - current working dir if None
base_dir=file_dir) # start archiving from here - cwd if None too
It gets everything correct except the folder directory wrong. For example, if file_dir = 'C:\Users\aaa\Desktop\test\bbb' The structure of the zip file will be:
Users
aaa
Desktop
test
bbb
And I wish it could be bbb/ only.
Any thoughts? I really appreciate your help.
I think the solution is to create the zipfile in a different directory. From there, something like
shutil.make_archive('zip_file', 'zip', 'C:\\Users\\test', "bbb")
should give you an archive of the bbb directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With