Read the data of CSV file inside Zip File without extracting the contents in Matlab

南笙酒味 提交于 2019-11-29 08:46:47

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.

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