Folder Backup To ZIP Program
Folder Backup To ZIP Program
To create a ZIP backup of a folder using Python. This program automatically names the backup and
import zipfile, os
def backupToZip(folder):
folder = os.path.abspath(folder)
number = 1
while True:
zipFilename = os.path.basename(folder) + '_' + str(number) + '.zip'
if not os.path.exists(zipFilename):
break
number += 1
print(f'Creating {zipFilename}...')
backupZip = zipfile.ZipFile(zipFilename, 'w')
backupZip.close()
print('Done.')
Procedure:
Expected Output:
A file like 'MyFolder_1.zip' will be created containing all files from the folder.
Console Output:
Creating MyFolder_1.zip...
Done.