Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

zip

unzip

matlab

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..?

like image 547
Chandra Sekhar K Avatar asked Oct 27 '25 22:10

Chandra Sekhar K


1 Answers

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.

like image 81
Konark K Avatar answered Oct 29 '25 15:10

Konark K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!