0

Here are the three file names (content inside should not matter in this example):

File1.txt
File2.txt
File3.txt

Here is my current code:

# create new .txt files
newFile1 = open('File1.txt', 'w')
newFile2 = open('File2.txt', 'w')
newFile3 = open('File3.txt', 'w')

# compress these three newly created files into a .zip folder

My goal is to create a .zip file compressing the three files listed above when the script is executed.

Here is my desired output (One new created .zip file):

CompressedFolder.zip
bbsmfb
  • 73
  • 6
  • 3
    Python has the zipfile library https://docs.python.org/3/library/zipfile.html Open a zip file and write your three files to it. – scotty3785 Dec 19 '21 at 09:27
  • 1
    You'll find [this](https://stackoverflow.com/questions/39767904/create-zip-archive-with-multiple-files) helpful – DarkKnight Dec 19 '21 at 09:28

1 Answers1

0

You should be able to use:

import zipfile 
# your code here
with ZipFile('spam.zip', 'w') as myzip:
    myzip.write('eggs.txt')

As in here: https://docs.python.org/3/library/zipfile.html