This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Compress files into zip file


entrynames = zip(zipfile,files,rootfolder)


zip(zipfile,files) creates a zip file with the name zipfile from the list of files and folders specified in files. Folders recursively include all of their content.

zip(zipfile,files,rootfolder) specifies the path for files relative to rootfolder instead of the current folder.

entrynames = zip(zipfile,files,rootfolder) returns a cell array of character vectors containing the names of the files in zipfile. Specifying rootfolder is optional.

Input Arguments


Name of the zip file, specified as a character vector. If zipfile has no extension, MATLAB® appends the .zip extension.

If files includes relative paths, the zip file also contains relative paths. The zip file does not include absolute paths.


List of files or folders to include in zipfile, specified as a character vector or a cell array of character vectors.

Individual files that are on the MATLAB path can be specified as partial path names. Otherwise an individual file can be specified relative to the current folder or with an absolute path.

Folders must be specified relative to the current folder or with absolute paths. On UNIX® systems, folders can also start with ~/ or ~username/, which expands to the current user's home folder or the specified user's home folder, respectively. The wildcard character * can be used when specifying files or folders, except when relying on the MATLAB path to resolve a file name or partial path name.


Root of the paths for the files to zip, specified as a character vector.

Relative paths in the zip file reflect the relative paths in files, and do not include path information from rootfolder.

Default: current folder ('.')

Output Arguments


Cell array of character vectors containing the paths to the files in zipfile. If files includes relative paths, entrynames also contains relative paths.


collapse all

Create a zip file of the file membrane.m. Save the zip file in the current folder.


Zip the files membrane.m and logo.m into a file named


Zip all .m and .mat files in the current folder to the file


Zip the contents of all subfolders of a folder, and store the relative paths in the zip file.

Create a folder myfolder containing a subfolder mysubfolder and the files membrane.m and logo.m.

mkdir myfolder;
cd myfolder;
mkdir mysubfolder;
cd ..

Zip the contents of all subfolders of myfolder.


Suppose that you have files thesis.doc and defense.ppt in d:/PhD. Zip these files into, one level up from the current folder.


Create a zip archive of a Web page.

Locate the list of files at the MATLAB® Central File Exchange uploaded within the past 7 days, that contain "Simulink."

filex = '';
params = {'duration','7','term','simulink'};

Save the Web content to a file.


Create a zip archive of the retrieved Web page, using the zip function. zip creates a zip archive named that contains the file, contains_simulink.html.



To zip files in the Current Folder browser, select the files, right-click to open the context menu, and then select Create Zip File.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?