我有一个带有700k dicom图像的.zip文件。目前,我的代码提取与 file_list 中的文件名匹配的文件,并将其保存在另一个位置。
我的目标是做相反的事情,即从.zip文件中删除与 file_list 中的文件不匹配的文件。
我该怎么做?以及如何从zip文件中删除文件而不将其保存在其他位置?
import zipfile
file_list = ["hi.dcm","hello.dcm"]
with zipfile.ZipFile('myzip.zip','r') as file:
#I want to parse the .zip and delete (not save at another location) files that aren't in file_list
for f in file_list:
file.extract('name/training/' + f,'./upload')