Unzip all zipped files in a folder to that same folder using Python 2.7.5

前端 未结 4 715
小蘑菇
小蘑菇 2021-01-30 18:15

I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder

4条回答
  •  不思量自难忘°
    2021-01-30 18:42

    You need to construct a ZipFile object with the filename, and then extract it:

        zipfile.ZipFile.extract(item)
    

    is wrong.

        zipfile.ZipFile(item).extractall()
    

    will extract all files from the zip file with the name contained in item.

    I think you should more closely read the documentation to zipfile :) but you're on the right track!

提交回复
热议问题