0

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
Community
  • 1
  • 1
Clanrat
  • 43
  • 6
  • What is not working with the code? – Daniel Jul 02 '15 at 09:47
  • @Dan, only a minor typo. @Clanrat, just change the line `while entries.hasNext` with `while entries.hasMoreElements` and everything works fine. It's actually quite a nice trick. Although one important thing not mentioned in the linked code: Do not forget to **close** the java zipfile after use (`zipFile.close`) or it will be locked until you close Matlab. – Hoki Jul 02 '15 at 09:57
  • @Hoki, thank you! Worked perfectly! – Clanrat Jul 02 '15 at 10:23
  • possible duplicate of [Read the data of CSV file inside Zip File without extracting the contents in Matlab](http://stackoverflow.com/questions/23131163/read-the-data-of-csv-file-inside-zip-file-without-extracting-the-contents-in-mat) – nkjt Jul 02 '15 at 10:25

0 Answers0