Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

zip - Compress files into zip file

Syntax

zip(zipfile,files)
zip(zipfile,files,rootfolder)
entrynames = zip(...)

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. If files includes relative paths, the zip file also contains relative paths. The zip file does not include absolute paths.

zipfile is a string specifying the name of the zip file. If zipfile has no extension, MATLAB appends the .zip extension.

files is a string or cell array of strings containing the list of files or folders included 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.

zip(zipfile,files,rootfolder) specifies the path for files relative to rootfolder instead of the current folder. Relative paths in the zip file reflect the relative paths in files, and do not include path information from rootfolder.

entrynames = zip(...) returns a string cell array of the names of the files contained 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 demos folder. Save the zip file in tmwlogo.zip in the current folder.

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

Run zip for the files membrane.m and logo.m and save the zip file, tmwlogo.zip, in the specified folder. The source files are on the MATLAB search path.

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

Zip Selected Files

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

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

Zip a Folder

Run zip for the folder mywork, which is a subfolder of the current folder. The zip file myfiles.zip recursively includes the contents of all subfolders of mywork, and stores the relative paths.

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

Zip Between Folders

Run zip for the files thesis.doc and defense.ppt, which are located in d:/PhD, to the zip file thesis.zip in the folder one level up from the current folder.

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

See Also

gzip, gunzip, tar, untar, unzip

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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