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

Python Zip File Assgn

The document describes a Python program that creates a backup of a folder by compressing its contents into a .zip file. It defines a function called backup_folder that takes a folder name, retrieves its absolute path, and compresses all files and subfolders into a .zip file. The program executes the backup process for two specific folders: example_folder and xyz_folder.

Uploaded by

angelotommy006
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

Python Zip File Assgn

The document describes a Python program that creates a backup of a folder by compressing its contents into a .zip file. It defines a function called backup_folder that takes a folder name, retrieves its absolute path, and compresses all files and subfolders into a .zip file. The program executes the backup process for two specific folders: example_folder and xyz_folder.

Uploaded by

angelotommy006
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
You are on page 1/ 2

Assignment-1

--------------------------------------------------------------------------------------------------------------------------------------

Program-2 Backing up a folder into a zip file.


Main program

Output
Before Execu ng
A er Execu ng

This Python program creates a backup of a folder by compressing its contents into a .zip
file.
1. It defines a func on called backup_folder that takes the name of a folder
as input.
2. Inside the func on:
o It gets the absolute path of the folder.
o It creates a .zip file with the same name as the folder (e.g., backing
up example_folder will create example_folder.zip).
3. It then goes through all files inside the folder (including subfolders) using
os.walk().
4. For each file it finds, it adds that file to the .zip file using the zipfile module.
5. Finally, it runs this backup process for two folders: example_folder and
xyz_folder.

You might also like