Home » Questions » Computers [ Ask a new question ]

How to create a zip file compatible with Windows under Linux

How to create a zip file compatible with Windows under Linux

I need to make a zip file available to all my Windows users visitors, so I naively produced a zip file with the Unix zip command (let's call it madeinlinux.zip).

Asked by: Guest | Views: 387
Total answers/comments: 4
bert [Entry]

zip -Z sets the compression option. -Z store is the most trivial one, as it doesn't compress at all. This is useful when you're using zip as an alternative for tar, or when troubleshooting. In this case you should try to see if an uncompressed archive is usable from Windows. If that is usable, you know that you'll have to pick a non-default compression option.
bert [Entry]

Had a similar issue recently with files produced from a perl script. Found that native windows zip (tested Windows 7 only) incorrectly handles paths with a leading slash and displays an empty zipfile. Solution was to strip the leading slash before adding files. Perhaps some versions of the linux zip command store file paths with leading slashes.
Had a similar issue recently with files produced from a perl script. Found that native windows zip (tested Windows 7 only) incorrectly handles paths with a leading slash and displays an empty zipfile. Solution was to strip the leading slash before adding files. Perhaps some versions of the linux zip command store file paths with leading slashes.
bert [Entry]

"Here is a python script that I am using to zip some files. It has been tested on ubuntu and Vista. A zip generated on Ubuntu opens with the Vista zipper.

I think that I had a similar issue in the past and it was because the zip format was not ZIP_DEFLATED. I am not sure. I will check that.

I hope it helps

import zipfile
import glob, os, sys

class ZipArchive:

def zip_it(self, dirName, files):
dirNamePrefix = dirName+""/*""
for filename in glob.glob(dirNamePrefix):
if os.path.isfile(filename) and (not self.exclude_svn or (filename.find("".svn\\"")==-1)):
print filename
name = filename[len(self.folder)+1:]
self.archive.write(filename, name, zipfile.ZIP_DEFLATED)

def run(self, folder, name, exclude_svn):
self.exclude_svn = exclude_svn
self.folder = folder
self.archive = zipfile.ZipFile(name+"".zip"", ""w"")
os.path.walk(self.folder, ZipArchive.zip_it, self)
self.archive.close()

if __name__ == ""__main__"":
if (len(sys.argv)==1):
print ""usage zipit folder [name] [svn:yes|no]""
else:
name = sys.argv[1]
exclude_svn = False

if (len(sys.argv)>2): name = sys.argv[2]
if (len(sys.argv)>3): exclude_svn = (sys.argv[3]==""no"")

arch = ZipArchive()
arch.run(sys.argv[1], name, exclude_svn)
print ""done"""
bert [Entry]

There is probably a problem in your file transference from Linux to Windows. If you´re using FTP, try setting a binary transfer (bin command in Windows, before the transference of your files from Linux to Windows).