Adding files from other directories to zip root directory with ZipFile

Viewed 10

This seems like a fairly trivial question but I wasn't able to figure it out when I last worked on this project months ago, and I'm still not able to figure it out.

I have the following code

z = zipfile.ZipFile(make_file_safe(chapter_name) + '.cbz', 'a')
    for file in os.listdir('tmp'):
        z.write('tmp/' + file)
        os.remove('tmp/' + file)

What I am trying to do is take all the files in the tmp directory and add them to the root zip directory (so it would look something like File.zip/1.jpg, but no matter what I do it always end up as File.zip/tmp/1.jpg. If I try to change any of the directories in z.write, it isn't able to find the file anymore.

0 Answers
Related