zip

Compresses files and folders into a zip archive.

Category: Programming > Files and Folders

Syntax

zip(zipfilename, files)

Creates zipfilename with the given files.

zip(zipfilename, files, rootfolder)

Takes files relative to rootfolder.

entries = zip(___)

Also returns the names stored in the archive.

Description

A zip archive gathers many files, with their relative paths, into one compressed file. Folder structure is kept, so extracting with unzip recreates it. The original files stay where they are.

Input arguments

zipfilename
Archive name; .zip is added if missing.
files
A file or folder name, a wildcard pattern, or a cell array of them. A folder is added with its contents.
rootfolder
Folder in which files are looked up.

Output arguments

entries
Cell array with the files stored.

Example

Zipping two files

writelines('red', 'a.txt');
writelines('blue', 'b.txt');
entries = zip('colors', {'a.txt', 'b.txt'})
isfile('colors.zip')
Output
entries = 1×2 cell

    {'a.txt'}    {'b.txt'}
ans = logical
   1

See also

unzip tar gzip untar