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(zipfile,files)
zip(zipfile,files,rootfolder)
entrynames = zip(zipfile,files,rootfolder)

Description

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

zipfile

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.

files

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.

rootfolder

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

entrynames

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

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');

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

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

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

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

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;
movefile('membrane.m','myfolder');
movefile('logo.m','myfolder');
cd myfolder;
mkdir mysubfolder;
cd ..

Zip the contents of all subfolders of myfolder.

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

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

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

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 = 'http://www.mathworks.com/matlabcentral/fileexchange/';
params = {'duration','7','term','simulink'};

Save the Web content to a file.

urlwrite(filex,'contains_simulink.html','get',params);

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

zip('simulink_matches.zip','contains_simulink.html');

Alternatives

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?