I have number of Zip Files {'File1.zip', 'File2.zip', 'File3.zip',..., 'FileN.zip'}
in which each zip file contains a Data.csv
file. I want to read the data in 'Data.csv'
of each Zip file without having to extract the Zip files' contents. Is this possible..?
Asked
Active
Viewed 3,968 times
4

Chandra Sekhar K
- 317
- 7
- 18
-
You can extract the file with the `unzip` command, read it, and delete it later if you don't want it. – buzjwa Apr 17 '14 at 10:55
-
My thought is instead of extracting or deleting....whether we can directly read the contents using actxserver application or java components in matlab.... – Chandra Sekhar K Apr 17 '14 at 11:03
-
That's an idea. You should edit the question to include this possible method. – buzjwa Apr 17 '14 at 11:05
1 Answers
4
Certainly Winzip / 7zip / Winrar do not have COM interface component which can invoke directly unlike word, excel an other application.
Hence @Java is appropriate
Idea is don't extract files physically , however create absolute path of file such that windows consider as physical presence of File (similar to ~tmp file)
here the code
zipFilename = 'Ex.zip';
zipJavaFile = java.io.File(zipFilename);
% Create a Java ZipFile
zipFile = org.apache.tools.zip.ZipFile(zipJavaFile);
% Extract the entries from the ZipFile.
entries = zipFile.getEntries;
cnt = 1;
% Get Zip File Paths
while entries.hasNext
tempObj = entries.nextElement;
file{cnt,1} = tempObj.getName.toCharArray';
cnt = cnt+ 1;
end
% Extract File Name
ind = regexp(file,'$*.csv$');
ind = find(~cellfun(@isempty,ind)); % Find Non Empty Cell Index
file = file(ind);
% Create Absolute Path so that Windows consider as Directory
file = cellfun(@(x) fullfile('.',x),file,'UniformOutput',false);
% Now Operate Any thing on File.

Konark K
- 147
- 8
-
1It is may be java version dependent but I have to use `while entries.hasMoreElements` instead of `while entries.hasNext` to get it to work. Nice trick otherwise. Don't forget to mention to **close** the java zipfile after use (`zipFile.close`) or it will be locked until you close Matlab. – Hoki Jul 02 '15 at 10:00