Main Content

unzip

Extract contents of zip file

Description

example

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

If a file exists with the same name and the file is not read-only, MATLAB® overwrites it. Otherwise, MATLAB issues a warning. On Microsoft® Windows® platforms, the hidden, system, and archive attributes are not set.

example

unzip(zipfilename,outputfolder) extracts zipfilename into outputfolder. If outputfolder does not exist, MATLAB creates it.

example

filenames = unzip(___) returns a cell array of character vectors containing the names of the extracted files.

Examples

collapse all

Create a zip file and extract it to the folder archive.

Create the zip file examples.zip containing example MAT-files.

zip('examples.zip','*.mat',...
    fullfile(matlabroot,'toolbox','matlab','demos'))

Extract examples.zip to the folder archive.

exampleFiles = unzip('examples.zip','archive')
exampleFiles = 1×41 cell
    {'archive\accidents.mat'}    {'archive\airfoil.mat'}    {'archive\airlineResults.mat'}    {'archive\cape.mat'}    {'archive\census.mat'}    {'archive\clown.mat'}    {'archive\detail.mat'}    {'archive\dmbanner.mat'}    {'archive\durer.mat'}    {'archive\earth.mat'}    {'archive\fatalities.mat'}    {'archive\fluidtemp.mat'}    {'archive\flujet.mat'}    {'archive\gatlin.mat'}    {'archive\gatlin2.mat'}    {'archive\integersignal.mat'}    {'archive\logo.mat'}    {'archive\mandrill.mat'}    {'archive\mapredout.mat'}    {'archive\membrane.mat'}    {'archive\mri.mat'}    {'archive\noisyecg.mat'}    {'archive\patients.mat'}    {'archive\penny.mat'}    {'archive\quake.mat'}    {'archive\seamount.mat'}    {'archive\spine.mat'}    {'archive\stocks.mat'}    {'archive\tetmesh.mat'}    {'archive\topo.mat'}    {'archive\topography.mat'}    {'archive\trimesh2d.mat'}    {'archive\trimesh3d.mat'}    {'archive\truss.mat'}    {'archive\usapolygon.mat'}    {'archive\usastates.mat'}    {'archive\usborder.mat'}    {'archive\vibesdat.mat'}    {'archive\west0479.mat'}    {'archive\wind.mat'}    {'archive\xpmndrll.mat'}

Download and extract a zip file from a URL to a local folder.

Suppose you have the zip file example_file.zip stored at the URL http://example.com/example_file.zip. Download and extract the file to the desired local folder, example_folder.

url = 'http://example.com/example_file.zip';
unzip(url, 'example_folder');

Input Arguments

collapse all

Name of zip file to extract from, specified as a character vector or a string scalar. If zipfilename has no extension, MATLAB searches for zipfilename appended with .zip.

zipfilename must include a path relative to the current folder or an absolute path.

If zipfilename is a URL, zipfilename must include the protocol type (for example, http://). MATLAB downloads the URL to the temporary folder on your system, and then it deletes the URL on cleanup.

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

Data Types: char | string

Target folder for the extracted files, specified as a character vector or a string scalar.

Data Types: char | string

Output Arguments

collapse all

Names of extracted files, returned as a cell array of character vectors. If outputfolder specifies a relative path, filenames contains the relative path. If outputfolder specifies an absolute path, filenames contains the absolute path.

Tips

  • To extract a zip file that contains non-7-bit ASCII characters, extract the file on a machine that has the appropriate language/encoding settings.

Version History

Introduced before R2006a

expand all