About zipfile on WinXP
Justin Ezequiel
justin.mailinglists at gmail.com
Wed Jan 4 05:13:54 EST 2006
here's a small script I wrote and use
note the line
arcname = os.path.splitdrive(p)[-1].lstrip(os.sep)
if I comment out `.lstrip(os.sep)`, I get a zip file like rzed
describes
###############################
import sys
import zipfile
import time
import os
if __name__ == '__main__':
pths = sys.argv[1:]
assert pths, 'usage: %s file1 [file2 [file3 ...]]' % sys.argv[0]
zpth = os.path.abspath(time.strftime('%Y%m%d%H%M%S.zip'))
zf = zipfile.ZipFile(zpth, 'w', zipfile.ZIP_DEFLATED)
for p in pths:
p = os.path.abspath(p)
arcname = os.path.splitdrive(p)[-1].lstrip(os.sep)
zf.write(p, arcname)
print arcname, p
zf.close()
print '%s files written to %s' % (len(pths), zpth)
###############################
More information about the Python-list
mailing list