Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Added zip file extractor to basic scripts #222

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Basic-Scripts/Zip_file_extractor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Extract zip files

This script takes a zip file as input and extracts its content into a separate folder.
The folder is named same as the input zip file and is saved in the current directory

### How to use this?
Just type the following in the command prompt:

python zip_file_extractor.py -l <Your zip file>

Example:

python zip_file_extractor.py -l Awesome.zip

<p align = "center">
<img src="sample.PNG" alt="sample">
</p>
Binary file added Basic-Scripts/Zip_file_extractor/sample.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions Basic-Scripts/Zip_file_extractor/zip_file_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import zipfile
import sys
import argparse

# Code to add the cli
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--zippedfile", required=True, help="Zipped file")
args = vars(parser.parse_args())

#Catching the user defined zip file
zip_file = args['zippedfile']

file_name = zip_file

#To check if the entered zip file is present in the directory
if os.path.exists(zip_file) == False:
sys.exit("No such file present in the directory")

#Function to extract the zip file
def extract(zip_file):
file_name = zip_file.split(".zip")[0]
if zip_file.endswith(".zip"):

#Will use this to save the unzipped file in the current directory
current_working_directory = os.getcwd()
new_directory = current_working_directory + "/" + file_name
#Logic to unzip the file
with zipfile.ZipFile(zip_file, 'r') as zip_object:
zip_object.extractall(new_directory)
print("Extracted successfully!!!")
else:
print("Not a zip file")

extract(zip_file)