Skip to Main Content Skip to Search
Product Documentation

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 string cell array of the names of the files contained in zipfile. Specifying rootfolder is optional.

Input Arguments

zipfile

String that specifies the name of the zip file. 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

String or cell array of strings containing the list of files or folders to include in zipfile.

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

String that specifies the root of the paths for the files to zip.

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 strings that contain the paths to the files in zipfile. If files includes relative paths, entrynames also contains relative paths.

Examples

Zip a File

Create a zip file of the file membrane.m, which is in the MATLAB general folder. Save the zip file tmwlogo.zip in the current folder:

file = fullfile(matlabroot,'toolbox','matlab','general','membrane.m');
zip('tmwlogo',file);

Zip Selected Files

Suppose that your system has a folder named d:/myfiles. Zip the files membrane.m and logo.m, which are on the MATLAB search path, into a file named tmwlogo.zip:

myfile = fullfile('d:','myfiles','tmwlogo.zip');
zip(myfile,{'membrane.m','logo.m'});

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

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

Zip a Folder

Suppose that your current folder contains a subfolder named mywork. Zip the contents of all subfolders of mywork, and store the relative paths in the zip file:

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

Zip Between Folders

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

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

gunzip | gzip | tar | untar | unzip

  


» Learn more
» Download free kit
» Get trial software

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS