Extracting specific file from zip in matlab

谁说胖子不能爱 提交于 2019-12-13 05:51:34

问题


Currently I have a zipfile containing several thousand .xml files, extracted the folder is 1.5gb in size. I have a function that matches data with specific files inside this zip file. I then want to read this specific file and extract additional data.

My question: Is there any way to extract these specific files from the archive without unzipping the entire archive?

The built in unzip.m function can only be used to unzip the entire file so it won't work so I am thinking I have to use the COM interface or some other approach.

Matlab version: R2013a

While searching for solutions I found this:Read the data of CSV file inside Zip File without extracting the contents in Matlab

But I can't get the code in the answer to work for my situation

Edit:

Credit to Hoki and Intelk

zipFilename = 'HMDB.zip';
zipJavaFile = java.io.File(zipFilename);
zipFile=org.apache.tools.zip.ZipFile(zipJavaFile);
entries=zipFile.getEntries;
cnt=1;
while entries.hasMoreElements
    tempObj=entries.nextElement;
    file{cnt,1}=tempObj.getName.toCharArray';
    cnt=cnt+1;
end
ind=regexp(file,'$*.xml$');
ind=find(~cellfun(@isempty,ind));
file=file(ind);
file = cellfun(@(x) fullfile('.',x),file,'UniformOutput',false);

And not forgetting the

zipFile.close

来源:https://stackoverflow.com/questions/31180208/extracting-specific-file-from-zip-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!