1

I got more than 1000 zip files in the same folder with naming convention output_MOJIBAKE

Example name: output_0aa3199eca63522b520ecfe11a4336eb_20210122_181742

How can I unzip them using Python?

Shubham Agrawal
  • 51
  • 1
  • 11
ckkkkkkk
  • 11
  • 1
  • 3
  • 2
    Use this https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory to get the list of files, then use this https://stackoverflow.com/questions/3451111/unzipping-files-in-python to unzip each one in a loop. – Aziz Aug 06 '21 at 10:36

1 Answers1

4

Try this and let me know if it worked.

import os
import zipfile

path = 'path/to/your/zip/files'

os.chdir(path)

for file in os.listdir('.'):
    with zipfile.ZipFile(file, 'r') as zip_ref:
        zip_ref.extractall('.')
Ayush Gupta
  • 1,166
  • 2
  • 9
  • 25