0

I want to put a file in every file of .txt, .mp3, and mp4 files.

import zipfile
import os
path = "G:"
file_zip = zipfile.ZipFile(path+'\\archive.zip', 'w')
for folder, subfolders, files in os.walk(path):
    for file in files:
        if file.endswith('.jpg,.txt,.mp3,.mp4'):
            file_zip.write(os.path.join(folder, file), os.path.relpath(os.path.join(folder,file), path), compress_type = zipfile.ZIP_DEFLATED)

file_zip.close()  

When I open the zip file, the zip file is empty!

CristiFati
  • 38,250
  • 9
  • 50
  • 87
Mr_Zed
  • 3
  • 4

1 Answers1

0

Try changing:

if file.endswith('.jpg,.txt,.mp3,.mp4'):

to:

if file.endswith(('.jpg', '.txt', '.mp3', '.mp4')):
sneep
  • 1,828
  • 14
  • 19