Main Content


Compress files into GNU zip files



gzip(filenames) compresses the contents of the specified files and folders into GNU zip files with the file extension .gz. gzip recursively compresses the content in folders. gzip places each output file to the same folder as the input file.


gzip(filenames,outputfolder) places the resulting GNU zip files into outputfolder. If outputfolder does not exist, MATLAB® creates it.


entrynames = gzip(___) returns a cell array of character vectors containing the relative path names of all resulting files. You can use this syntax with any of the input argument combinations in the previous syntaxes.


collapse all

Compress all files with a .m and .mlx extension in the current folder and store the results in the archive folder.

compressedfiles = gzip({'*.m','*.mlx'},'archive');
compressedfiles = 1x1 cell array

Create a GNU zip file of a folder including all subfolders, and store the relative paths in the file.

Create a folder myfolder containing a subfolder mysubfolder and the files membrane.m and logo.m.

mkdir myfolder;
cd myfolder;
mkdir mysubfolder;
cd ..

Create a GNU zip file of the contents of myfolder, including all subfolders.

gzippedfiles = gzip('myfolder');

Input Arguments

collapse all

Names of files or folders to compress, specified as a character vector, a cell array of character vectors, or a string array.

Files that are on the MATLAB path can include a partial path. Otherwise, files must include a path relative to the current folder or an absolute path.

Folders must include a path relative to the current folder or an absolute path. On UNIX® systems, folders also can start with ~/ or ~username/, which expands to the current user's home folder or the specified user's home folder, respectively. You can use the wildcard character * when specifying files or folders, except when relying on the MATLAB path to resolve a file name or partial path name.

Data Types: char | string

Target folder for the compressed files, specified as a character vector or a string scalar.

Data Types: char | string

Output Arguments

collapse all

Names of compressed files, returned as a cell array of character vectors. Each element in entrynames is the path of an entry relative to the archive.

Version History

Introduced before R2006a

See Also

| | | |