Documentation Center

  • Trial Software
  • Product Updates

unzip

Extract contents of zip file

Syntax

unzip(zipfilename)
unzip(zipfilename,outputdir)
filenames = unzip(zipfilename,outputdir)

Description

unzip(zipfilename) extracts the archived contents of zipfilename into the current folder, preserving the files' attributes and timestamps. The unzip function can extract files from your local system or files from an Internet URL.

unzip(zipfilename,outputdir) extracts the contents of zipfilename into the folder outputdir.

filenames = unzip(zipfilename,outputdir) returns the names of the extracted files in the string cell array filenames. Specifying outputdir is optional.

Input Arguments

zipfilename

String that specifies the name of the zip file.

If zipfilename does not include the full path, unzip searches for the file in the current folder and along the MATLAB® path. If you do not specify the file extension, unzip appends .zip.

If you are downloading a URL, zipfilename must include the protocol type (for example, http://). The unzip function downloads the URL to the temporary folder on your system, and deletes the URL on cleanup.

outputdir

String that specifies the target folder for the extracted files.

Default: current folder ('.')

Output Arguments

entrynames

Cell array of strings that contain the paths of the extracted files.

If outputdir specifies a relative path, filenames contains the relative path. If outputdir specifies an absolute path, filenames contains the absolute path.

Examples

Copy the example MAT-files to the folder archive:

% Zip the example MAT-files to examples.zip
zip('examples.zip','*.mat',...
    fullfile(matlabroot,'toolbox','matlab','demos'))

% Unzip examples.zip to the folder 'archive'
unzip('examples','archive')
 

Download Cleve Moler's "Numerical Computing with MATLAB" examples to the output folder ncm:

url ='http://www.mathworks.com/moler/ncm.zip';
ncmFiles = unzip(url,'ncm')

Alternatives

To extract files from a zip file using the Current Folder browser, select the zip file, right-click to open the context menu, and then select Extract.

More About

expand all

Tips

  • unzip does not support password-protected or encrypted zip archives.

  • If any files in the target folder have the same name as files in the zip file, and you have write permission to the files, unzip overwrites the existing files with the archived versions. If you do not have write permission, unzip issues a warning.

  • Extract files that contain non-7-bit ASCII characters on a machine that has the appropriate language/encoding settings.

See Also

| | | | |

Was this topic helpful?