Issue with zipfile and symbolic link

loial jldunn2000 at gmail.com
Tue May 30 03:45:46 EDT 2017


I am reading a list of pdf files from a directory which is a symbolic link and adding them to a zip file.

Issue I have is that the zip files are being added as empty directories rather than the actual pdf files.

My code is below. Any idea why this happening?

           # ZIP pdfs subdirectory if it exists

            sourcefile = self._dir + os.sep + "pdfs"
            targetname = "pdfs"

            if os.path.exists(sourcefile):
               zf.write(sourcefile,targetname, compress_type=compression)

               for file in os.listdir(sourcefile):
                   targetname = "pdfs" + os.sep + file
                   zf.write(sourcefile,targetname, compress_type=compression)

            # Close zip file

            zf.close()



More information about the Python-list mailing list