0% found this document useful (0 votes)
6 views3 pages

Exercise 07

The document outlines an exercise for a Python programming course focused on creating a program to back up a specified folder into a ZIP file. It includes a sample code that checks if the directory exists, creates a ZIP archive of the folder's contents, and provides output messages based on the success of the operation. The program utilizes modules such as os, sys, pathlib, and zipfile to accomplish the task.

Uploaded by

akasharadhyam
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)
6 views3 pages

Exercise 07

The document outlines an exercise for a Python programming course focused on creating a program to back up a specified folder into a ZIP file. It includes a sample code that checks if the directory exists, creates a ZIP archive of the folder's contents, and provides output messages based on the success of the operation. The program utilizes modules such as os, sys, pathlib, and zipfile to accomplish the task.

Uploaded by

akasharadhyam
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/ 3

BPLCK105B/205B | Introduction to Python Programming|

Subject Code: BPLCK105B/205B

Subject : Introduction to Python Programming

Exercise-07

Develop a program to backing Up a given Folder (Folder in a current working


directory) into a ZIP File by using relevant modules and suitable methods

PROGRAM

"""

Created on Sunday 02/07/2023

07BackFolderZip.py

Develop a program to backing Up a given Folder (Folder in a current


working

directory) into a ZIP

File by using relevant modules and suitable methods.

@author: Hanumanthu 4th sem Dept.Of CSE

"""

import os

import sys

import pathlib

import zipfile

Search Creators…. Page 1


BPLCK105B/205B | Introduction to Python Programming|

dirName = input("Enter Directory name that you want to backup : ")

if not os.path.isdir(dirName):

print("Directory", dirName, "doesn’t exists")

sys.exit(0)

curDirectory = pathlib.Path(dirName)

with zipfile.ZipFile("myZip.zip", mode="w") as archive:

for file_path in curDirectory.rglob("*"):

archive.write(file_path, arcname=file_path.relative_to(curDirectory))

if os.path.isfile("myZip.zip"):

print("Archive", "myZip.zip", "created successfully")

else:

print("Error in creating zip archive")

Search Creators…. Page 2


BPLCK105B/205B | Introduction to Python Programming|

OUTPUT

Procedure

1.Create a Simple Folder in your Directory

Folder name: demo

Search Creators…. Page 3

You might also like