0

I'm trying to zip a file in python, my code is:

import zipfile
f = zipfile.ZipFile('/home/tom/Desktop/test.csv.zip','w',zipfile.ZIP_DEFLATED)
f.write('/home/tom/Desktop/test.csv')
f.close()

It's working well, but inside my zip file I'm having the full path: /home/tom/Desktop/test.csv

How can I just get test.csv inside the zip file?

1

1 Answer 1

2

From docs:

ZipFile.write(filename[, arcname[, compress_type]])

Write the file named filename to the archive, giving it the archive name arcname (by default, this will be the same as filename, but without a drive letter and with leading path separators removed).

So...

f.write('/home/tom/Desktop/test.csv', 'test.csv')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.