0

I want to extract all files that have the same filetype from a zip file. I have this code:

from zipfile import ZipFile

counter = 0
with ZipFile('Video.zip', 'r') as zipObject:
    listOfFileNames = zipObject.namelist()
    for fileName in listOfFileNames:
        if fileName.endswith('.MXF'):
            zipObject.extract(fileName, 'Greenscreen')
            print('File ' + str(counter) + ' extracted')
            counter += 1
    print('All ' + str(counter) + ' files extraced')

The problem is that the zip file also has multiple sub-folders with the required .MXF files in them. Thus after running the script my Greenscreen folder also shows all sub-folders like this:

enter image description here

But i just need the files of the same file-type. So it should look like this: enter image description here

Toto
  • 89,455
  • 62
  • 89
  • 125
SimonDice
  • 19
  • 2
  • So your code does only extract files with .MXF, and your question is 'how to extract them into one folder and not into sub-folders?' – JeffUK Jun 16 '21 at 10:10
  • Yes. All .MXF fiels are in sub-folders in the zip. After running the script the sub-folders are still persistent. – SimonDice Jun 16 '21 at 10:14
  • 1
    I think this will answer your question https://stackoverflow.com/questions/4917284/extract-files-from-zip-without-keeping-the-structure-using-python-zipfile – JeffUK Jun 16 '21 at 10:16

0 Answers0