Documentation

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.

zip

Compress files into zip file

Syntax

zip(zipfilename,filenames)
zip(zipfilename,filenames,rootfolder)
entrynames = zip(___)

Description

example

zip(zipfilename,filenames) compresses the contents of filenames into the zip file zipfilename. zip recursively compresses the content in folders. The resulting zip file contains the paths of filenames relative to the current folder. The zip file does not store absolute paths.

example

zip(zipfilename,filenames,rootfolder) specifies the paths for filenames relative to rootfolder rather than the current folder.

example

entrynames = zip(___) returns a cell array of character vectors containing the names of the files included in zipfilename. You can use this syntax with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

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

zip('tmwlogo','membrane.m');

Compress the files membrane.m and logo.m into a file named tmwlogo.zip.

zippedfiles = zip('tmwlogo.zip',{'membrane.m','logo.m'});

Compress all .m and .mlx files in the current folder to the file backup.zip.

zip('backup',{'*.m','*.mlx'});

Compress the contents of a folder including all subfolders, 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;
movefile('membrane.m','myfolder');
movefile('logo.m','myfolder');
cd myfolder;
mkdir mysubfolder;
cd ..

Compress the contents of myfolder, including all subfolders.

zippedfiles = zip('myfiles.zip','myfolder');

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

zip('../thesis.zip',{'thesis.doc','defense.ppt'},'d:/PhD');

Input Arguments

collapse all

Name of zip file to create, specified as a character vector. If zipfilename does not have a .zip extension, MATLAB® appends the .zip extension.

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

Names of files or folders to compress, specified as a character vector or a cell array of character vectors. filenames must be smaller than 4 GB.

Files that are on the MATLAB path can include a partial path. Otherwise, files must include a path relative to the current folder or an absolute path.

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

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

Alternative Functionality

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

Introduced before R2006a

Was this topic helpful?