tar
Packs files and folders into a tar archive.
Category: Programming > Files and Folders
Syntax
tar(tarfilename, files)
Creates tarfilename containing files.
tar(tarfilename, files, rootfolder)
Takes files relative to rootfolder.
entries = tar(___)
Also returns the names stored in the archive.
Description
A tar archive stores many files and folders, with their relative paths, in a single file. By itself it does not compress; the gzip variants do. Use untar to extract it, and zip when you need the more widespread zip format.
Input arguments
tarfilename- Name of the archive. The extensions
.tar,.tgzand.tar.gzare recognized;.tgzand.tar.gzcompress the archive. 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
filesare looked up.
Output arguments
entries- Cell array of the files stored.
Example
Archiving a folder
mkdir data
writelines('1', 'data/a.txt');
writelines('2', 'data/b.txt');
entries = tar('bundle.tar', 'data')
Output
entries = 1×2 cell
{'data/a.txt'} {'data/b.txt'}