Skip paths when using zipfile-module
Fredrik Lundh
fredrik at effbot.org
Fri Jan 19 06:29:58 EST 2001
Thomas Weholt wrote:
> Just started using the zipfile-module in Python 2.0 and it works great, but
> I need to skip the path info. I want to create an archive with just the
> files in them, stored without paths. Didn't see any options/info about this
> in the docs. Any clues ?
pass the name you want in the archive as the second
argument to the write method:
# zipfile-example-3.py
# (from the upcoming second edition of the eff-bot guide)
import zipfile
import glob, os
file = zipfile.ZipFile("test.zip", "w")
for name in glob.glob("samples/*"):
file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
# -rest of example snipped-
Hope this helps!
Cheers /F
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list