Read files in zip file without unzipping
205 views (last 30 days)
Bob Hamans on 6 Jul 2011
Hi Etienne. I don't know if I understand your question but you just want to list the zip file contents without unzipping? The following code does just that:
function filelist = listzipcontents(zipFilename)
% Create a Java file of the ZIP filename.
zipJavaFile = java.io.File(zipFilename);
% Create a Java ZipFile and validate it.
zipFile = org.apache.tools.zip.ZipFile(zipJavaFile);
% Extract the entries from the ZipFile.
entries = zipFile.getEntries;
% Initialize the file list.
% Loop through the entries and add to the file list.
filelist = cat(1,filelist,char(entries.nextElement));
Robert Cumming on 6 Jul 2011
have you seen this thread - you could try what it suggests in your own copy of unzip.m - or send an enhancement request to Mathworks.
Its actually quite easy to update the m file(s):
1. Change the number of accepted input arguments to 3.
2. Handle the third input agument (say a cell array of requested files) or set to default (empty cell array)
3. Pass the 3rd argument into the private function extractArchive
4. In the private function do a strcmp on the entryName and your cell array of requested file(s) - if match found extract, if not skip to next (use continue in the while loop)
Brunno Machado de Campos on 11 Jan 2018
Hi, If anyone is until interested, for zip, on Windows (where I tested):
a = fopen('ZIPFILENAME.zip','r');
c2 = fread(a,'uint8=>uint8');
zipname = char(c2(31:31+c2(27)-1));
zipname = strcat(zipname')