我想从Python中解压缩.zip中的特定文件夹:
例如,archive.zip包含的文件夹foo和bar,我想解压缩foo到一个特定的位置,保持它的文件夹结构.
kas*_*sky 25
检查zipfile模块.
对于你的情况:
import zipfile
archive = zipfile.ZipFile('archive.zip')
for file in archive.namelist():
if file.startswith('foo/'):
archive.extract(file, 'destination_path')
Run Code Online (Sandbox Code Playgroud)