Search code examples
pythonzip

python zipfile directory gets copied too


I'm experimenting with the zipfile module of python the code i currently use is this:

z = zipfile.ZipFile("jar/algorithms.jar", "w")
z.write('directory/QuickSort.class')

The problem is that my file is added to the jar as following:

algorithms.jar>directory>QuickSort.class

What I want is: algorithms.jar>QuickSort.class

How can I achieve this?


Solution

  • You can use the arcname parameter - see http://docs.python.org/library/zipfile.html#zipfile.ZipFile.write

    z.write("directory/QuickSort.class","QuickSort.class")