Flat files within a zipfile in Python -
i doing:
z = zipfile.zipfile('myzip.zip', 'w') z.write('/some/path/mytxt1.txt') z.write('/some/other/path/mytxt2.txt') z.close()
this preserving file paths within zip. want desired files sit flat in zip file. how can this?
zipfile.write()
takes second argument, arcname
. set os.path.basename()
of first argument remove path:
def zip_write(zip, filename): zip.write(filename, os.path.basename(filename)) z = zipfile.zipfile('myzip.zip', 'w') zip_write(z, '/some/path/mytxt1.txt') zip_write(z, '/some/other/path/mytxt2.txt') z.close()
Comments
Post a Comment