zip - Compress files into zip file

Syntax

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

Description

zip(zipfile,files) creates a zip file with the name zipfile from the list of files and directories specified in files. Relative paths are stored in the zip file, but absolute paths are not. Directories recursively include all of their content.

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 directories 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 directory or with an absolute path.

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

zip(zipfile,files,rootdir) allows the path for files to be specified relative to rootdir rather than the current directory.

entrynames = zip(...) returns a string cell array of the names of the files contained in zipfile. If files contains a relative path, entrynames also contains the relative path.

Examples

Zip a File

Create a zip file of the file guide.viewlet, which is in the MATLAB demos directory. It saves the zip file in d:/mymfiles/viewlet.zip.

file = fullfile(matlabroot,'demos','guide.viewlet');
zip('d:/mymfiles/viewlet.zip',file)

Run zip for the files guide.viewlet and import.viewlet and save the zip file in viewlets.zip. The source files and zipped file are in the current directory.

zip('viewlets.zip',{'guide.viewlet','import.viewlet'})

Zip Selected Files

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

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

Zip a Directory

Run zip for the directory D:/mymfiles and its contents to the zip file mymfiles in the directory one level up from the current directory.

zip('../mymfiles','D:/mymfiles')

Zip Between Directories

Run zip for the files thesis.doc and defense.ppt, which are located in d:/PhD, to the zip file thesis.zip in the current directory.

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

See Also

gzip, gunzip, tar, untar, unzip


[1] UNIX is a registered trademark of The Open Group in the United States and other countries.

  


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