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

Commit e08f365

Browse files
authored
Merge pull request #222 from AdityaJ7/extractor-basic
Added zip file extractor to basic scripts
2 parents c37da1f + 0079632 commit e08f365

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Extract zip files
2+
3+
This script takes a zip file as input and extracts its content into a separate folder.
4+
The folder is named same as the input zip file and is saved in the current directory
5+
6+
### How to use this?
7+
Just type the following in the command prompt:
8+
9+
python zip_file_extractor.py -l <Your zip file>
10+
11+
Example:
12+
13+
python zip_file_extractor.py -l Awesome.zip
14+
15+
<p align = "center">
16+
<img src="sample.PNG" alt="sample">
17+
</p>
35.7 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import zipfile
3+
import sys
4+
import argparse
5+
6+
# Code to add the cli
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("-l", "--zippedfile", required=True, help="Zipped file")
9+
args = vars(parser.parse_args())
10+
11+
#Catching the user defined zip file
12+
zip_file = args['zippedfile']
13+
14+
file_name = zip_file
15+
16+
#To check if the entered zip file is present in the directory
17+
if os.path.exists(zip_file) == False:
18+
sys.exit("No such file present in the directory")
19+
20+
#Function to extract the zip file
21+
def extract(zip_file):
22+
file_name = zip_file.split(".zip")[0]
23+
if zip_file.endswith(".zip"):
24+
25+
#Will use this to save the unzipped file in the current directory
26+
current_working_directory = os.getcwd()
27+
new_directory = current_working_directory + "/" + file_name
28+
#Logic to unzip the file
29+
with zipfile.ZipFile(zip_file, 'r') as zip_object:
30+
zip_object.extractall(new_directory)
31+
print("Extracted successfully!!!")
32+
else:
33+
print("Not a zip file")
34+
35+
extract(zip_file)

0 commit comments

Comments
 (0)