1

I started learn python and trying to create 'backup' app. Want to add files from chosen directory in zip archive, but I don't understand why zipfile.write adding the same files from directory in arhive non-stop? Also it add itself to archive.

import zipfile, os, pathlib, time
from os.path import basename

now = time.strftime('%H%M%S')
source3 = 'F:\oneMoreTry'

# create a ZipFile object
with zipfile.ZipFile(now + '.zip', 'w') as zipObj:
   # Iterate over all the files in directory
   for folderName, subfolders, filenames in os.walk(source3):
           for filename in filenames:
               # create complete filepath of file in directory
               filePath = os.path.join(folderName, filename)
               # Add file to zip
               zipObj.write(filePath, basename(filePath))
Twelfth641
  • 11
  • 1

0 Answers0