Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON Need Help with this python program. A good friend of yours has sent you a zip folder containing various images. He asked if you

PYTHON

Need Help with this python program. A good friend of yours has sent you a zip folder containing various images. He asked if you could write a program that will automatically unzip the file and rename all the files in the unzipped folder by using a prefix and a number. He would then like the folder re-named and zipped

The program will prompt the user the name of the zip file in the current folder to unzip, the desired prefix of the files within the folder to be re-named and the starting index for the files being re-named.

Example prompts:Enter your zip file name (xxxx.zip):Images.zipEnter the desired prefix for renaming your files:Img-Enter the starting number (integer) of your files to be named:1

From the example above, the specified my zip files was Images.zip. The files within unzipped file will be renamed with the prefix Img- The starting number for the files will be: 1

So, for this example, the Images.zip file will unzip to Images.All the files within the Images folder will be renamed: Img-1.xxx, Img-2.xxx,etc. where xxx is the file suffix.The program will next rename the Images folder to new_Images and zip the folder.

The program will need to make use of the following functions:main(), user_prompt(), zip(), and unzip(). The main() function can be broken down in in some smallerfunctions if desired

.In the main() function, the program should check to see if the zip file name, the file prefix and the starting numbers were passed to the program. If they were, the program can use that information to be passed to user_prompt() function which will do validation on the input passed to it.

The user_prompt() function will validate each of the 3 pieces information passed to it by looping on each prompt to the user until the information is valid.

Input File Name Checks:Input file names must be greater than 3 characters. Input file names provided must be checked if the file exists in the current folder.

Prefix Check- The prefix provided must be 3 or more characters

Starting Number Check: The starting number must be a positive integer

.The program will be using the following libraries: os, sys, shutil, zipfile

When zipping the folder, the program should use the compression=zipfile.ZIP_DEFLATED option.

##My Program so far

file = open('new_Images3.txt','w+')

file.write('Images')

file.close()

import zipfile

image_file = zipfile.ZipFile('Compressed_Image_Folder.zip','w')

image_file.write('Image-1.txt',compress_type=zipfile.ZIP_DEFLATED)

image_file.write('Image-2.txt',compress_type=zipfile.ZIP_DEFLATED)

image_file.write('Image-3.txt',compress_type=zipfile.ZIP_DEFLATED)

image_file.close()

zip_obj -zipfile.ZipFile('Compressed_Image_Folder.zip')

Thank you in advance, any help would be greatly appreciated!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago