How to unzip specific folder from a .zip with Python

后端 未结 1 545
一个人的身影
一个人的身影 2021-01-03 22:45

I am looking to unzip a particular folder from a .zip in Python:

e.g. archive.zip contains the folders foo and bar, I want to

相关标签:
1条回答
  • 2021-01-03 23:24

    Check zipfile module.

    For your case:

    import zipfile
    
    archive = zipfile.ZipFile('archive.zip')
    
    for file in archive.namelist():
        if file.startswith('foo/'):
            archive.extract(file, 'destination_path')
    
    0 讨论(0)
提交回复
热议问题