Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor ZIP File Extraction Python

I need to unzip a .ZIP archive. I already know how to unzip it, but it is a huge file and takes some time to extract. How would I print the percentage complete for the extraction? I would like something like this:

Extracting File
1% Complete
2% Complete
etc, etc
like image 552
Zac Brown Avatar asked Oct 24 '10 02:10

Zac Brown


1 Answers

You can just monitor the progress of each file being extracted with tqdm():

from zipfile import ZipFile
from tqdm import tqdm

# Open your .zip file
with ZipFile(file=path) as zip_file:

    # Loop over each file
    for file in tqdm(iterable=zip_file.namelist(), total=len(zip_file.namelist())):

        # Extract each file to another directory
        # If you want to extract to current working directory, don't specify path
        zip_file.extract(member=file, path=directory)
like image 169
RoadRunner Avatar answered Nov 09 '22 01:11

RoadRunner