0% found this document useful (0 votes)
2 views2 pages

Program 7

The document contains a Python script that creates a backup of a specified folder by compressing it into a ZIP file. It checks for existing ZIP files to avoid overwriting and adds all files from the folder to the new ZIP archive. The script is executed with a specified folder path for backup.

Uploaded by

Bhagyashree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Program 7

The document contains a Python script that creates a backup of a specified folder by compressing it into a ZIP file. It checks for existing ZIP files to avoid overwriting and adds all files from the folder to the new ZIP archive. The script is executed with a specified folder path for backup.

Uploaded by

Bhagyashree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import zipfile,os

def backupToZip(folder):

print('enter into function')

folder = [Link](folder)

number=1

while True:

zipFilename=[Link](folder)+'_'+str(number)+'.zip'

if not [Link](zipFilename):

break

number=number+1

print('creating %s...'%(zipFilename))

backupZip=[Link](zipFilename,'w')

for foldername,subfolders,filenames in [Link](folder):

print('Adding files in %s...' %(foldername))

[Link](foldername)

for filename in filenames:

newBase=[Link](folder)

if [Link](newBase) and [Link]('.zip'):

continue

[Link]([Link](foldername,filename))

[Link]()

print('done')

#Main program

backupToZip(r'C:\Users\Chandru\Desktop\backup')

OUTPUT
creating backup_1.zip...
Adding files in C:\Users\Chandru\Desktop\backup...
done

You might also like