Merge two zip files with python

I am trying to merge two zip files using python.

I worked until I realized that it does not behave when it comes to the symbolic links contained in the source zip file. Since I used zipfile.read () for each file, when I added it to a new zip file, it read a symbolic link and created a text file, not a symbolic link.

Does anyone know how to get python to keep a symbolic link from the source zip file when I write them to the target zip file?

Thanks.

+4
source share
1 answer

Here's how it should be done:

if os.path.islink(filePath): attr = zipfile.ZipInfo(filePath) attr.create_system = 3 # 3 for unix, 0 for windoze attr.external_attr = 2716663808L # to include file as a symlink newZip.writestr(attr, os.readlink(filePath)) 
+2
source

Source: https://habr.com/ru/post/1441337/


All Articles