'Can I prevent zipfile from creating a redundant directory when I archive multiple files?
In Python's zipfile module, when you create a zip file with only one file, it is correctly transformed into the unzipped form. But once I add another file, it is transformed into the redundant directory, and I muse traverse one step further to obtain a file I want.
For example:
import zipfile
a = zipfile.ZipFile("test.zip", "w")
a.write("test.txt")
a.close()
This creates a file test.zip. When I open it, it is transformed into test.txt, not test.
But the following code is transformed into test, not test.txt and test.csv:
import zipfile
a = zipfile.ZipFile("test.zip", "w")
a.write("test.txt")
a.write("test.csv")
a.close()
So can I prevent zipfile from creating the directory test?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
