Selective unzipping of files
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JS
el 30 de Oct. de 2019
Respondida: Mohammad Sami
el 1 de Nov. de 2019
I would like to selectively unzip a file within a large zipped folder without having to unzip the entire folder due to its size. It looks like I can do this through the MATLAB GUI; however, I need to automate this through code. I understand that I can do this in python by loading the zip file as an object and specifying in that object which file we would to exact. Is there a way to do something similar in MATLAB or is there simply an approach that can achieve the same result?
0 comentarios
Respuesta aceptada
Mohammad Sami
el 1 de Nov. de 2019
You will need to use java if you wish to extract only specified files
You can refer to java documentations at the following link.
zipFilename = 'abc.zip';
zipJavaFile = java.io.File(zipFilename);
zipFile = org.apache.tools.zip.ZipFile(zipJavaFile);
% entries = zipFile.getEntries; % to get all entries then iterate
entry = zipFile.getEntry('abcfolder/abcfile.txt'); % empty if not found
if(~isempty(entry))
inputstream = zipFile.getInputStream(entry);
outJavaFile = java.io.File(fullfile(pwd,'abcfolder/abcfile.txt'));
outStream = java.io.FileOutputStream(outJavaFile);
copier = com.mathworks.mlwidgets.io.InterruptibleStreamCopier.getInterruptibleStreamCopier;
copier.copyStream(inputstream, outStream);
outStream.close();
end
zipFile.close();
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Call Java from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!