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?
MATLAB: Selective unzipping of files
extractfileMATLABselectiveunzipzipped
Related Solutions
#java. Found a solution of the bug fix SMS page on mathwork.com. thanks
Workaround
Note: If you cannot launch MATLAB at all, please see Bug Report 1116607, "Cannot launch MATLAB 14a or earlier on OS X 10.10 Yosemite".
For MATLAB R2011a through R2014a only.
To install this patch, you need the name and password of an account with Administrator privileges.
Download the appropriate patch file for the version of MATLAB you wish to patch. Look for the file in your Downloads folder, the Desktop, or wherever your Web browser saves downloaded files. If your Web browser did not unzip the patch file for you, double-click the file in the Finder to unzip it. Double-click the .dmg file to mount the disk image. At the top level of the mounted disk image is an application such as R2014a_patch_1098655.app. Double-click to launch it. Select your MATLAB installation. Select the root folder of the install, for example, MATLAB_R2014a.app. Enter the name and password of an account with Administrator privileges. New Java class files will be installed in the java/patch/com/mathworks/widgets folder of your MATLAB installation. When the upgrade is complete, you can launch MATLAB. Fix
This bug was fixed as of R2014b(8.4).
If you have a current subscription to MathWorks Software Maintenance Service (SMS), you can download product updates. If not, learn more about MathWorks SMS.
Hi,
I would use JAVA to get what you want, e.g. the following example extract the .txt files in a zip files only (done with R2013b):
zipFile = org.apache.tools.zip.ZipFile('Untitled1.zip'); entries = zipFile.getEntries; while entries.hasMoreElements entry = entries.nextElement; entryName = char(entry.getName); [~,~,ext] = fileparts(entryName); if strcmp(ext,'.txt') inputStream = zipFile.getInputStream(entry); fileOutputStream = java.io.FileOutputStream(fullfile(pwd,entryName)); streamCopier = com.mathworks.mlwidgets.io.InterruptibleStreamCopier.getInterruptibleStreamCopier; streamCopier.copyStream(inputStream, fileOutputStream); fileOutputStream.close; inputStream.close; end end zipFile.close
UPDATED VERSION FOR SCANNING A FOLDER FOR ZIP FILES AND PROCESS ALL OF THEM
zipfolder = 'C:\Users\fhempel\Desktop\tmp';extractionfolder = 'C:\Users\fhempel\Desktop\tmp';zipfiles = dir([zipfolder,'\*.zip']);for i=1:numel(zipfiles) zipFile = org.apache.tools.zip.ZipFile(fullfile(zipfolder,zipfiles(i).name)); entries = zipFile.getEntries; while entries.hasMoreElements entry = entries.nextElement; entryName = char(entry.getName); [~,~,ext] = fileparts(entryName); if strcmp(ext,'.txt') inputStream = zipFile.getInputStream(entry); if ~exist(fullfile(extractionfolder,zipfiles(i).name(1:end-4)),'dir') mkdir(fullfile(extractionfolder,zipfiles(i).name(1:end-4))) end fileOutputStream = java.io.FileOutputStream(fullfile(extractionfolder,zipfiles(i).name(1:end-4),entryName)); streamCopier = com.mathworks.mlwidgets.io.InterruptibleStreamCopier.getInterruptibleStreamCopier; streamCopier.copyStream(inputStream, fileOutputStream); fileOutputStream.close; inputStream.close; end end zipFile.closeend
Best Answer