Python code to search for all the zip files in the directory and unzip them.

 Before 

After running the code.
Below is the Code.

# Program to fetch all the zip files and unzip them

import os,zipfile, pathlib

path_dir = 'F:/ck'
entries = pathlib.Path(path_dir)
files_present_dir = []
for entry in entries.iterdir():
    files_present_dir.append(entry.name) 
 
#print(*files_present_dir,sep="\n") 
l = len(files_present_dir)
for check_file in range(0,l):
    temp = files_present_dir[check_file]
    if temp.find('.zip') != -1:
        s = path_dir + '/' + temp
        with zipfile.ZipFile((s), 'r') as zip:
            zip.printdir()  #List all the files present in zip
            print('Extracting all the files...')
            zip.extractall(path='F:/ck')
            print('Done!!')

__author__ = "Hemant Kumar Chauhan"








Comments

Popular posts from this blog

Python GUI Classic Example using KivyMD and Kivy (ScreenManager, position, MD, Images, Carousel etc.)

PYTHON CODE TO CONVERT IMAGE FILE INTO PDF(Basic version)

Download Application to convert Image to Pdf (Simple to Use)