Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

untar

Extract contents of tar file

Syntax

untar(tarfilename)
untar(tarfilename,outputfolder)
filenames = untar(___)

Description

example

untar(tarfilename) extracts the archived contents of tarfilename into the current folder, preserving the attributes and timestamps of each file. untar can extract files from your local system or files from an Internet URL.

If a file exists with the same name and the file is not read-only, MATLAB® overwrites it. On Microsoft® Windows® platforms, MATLAB does not set the hidden, system, and archive attributes.

example

untar(tarfilename,outputfolder) extracts the archived contents of tarfilename into outputfolder. If outputfolder does not exist, MATLAB creates it.

example

filenames = untar(___) returns a cell array of character vectors containing the names of the extracted files. You can use this syntax with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Create a tar file, and then extract it to the folder backup.

Create a tar file of all the program files in the current folder.

tar('myfiles.tar.gz',{'*.m','*.mlx'});

Extract myfiles.tar.gz to the folder backup.

programFiles = untar('myfiles','backup')
programFiles = 1x3 cell array
    {'backup/myfile1.m'}    {'backup/myfile2.m'}    {'backup/ExtractT...'}

Download and extract an archive file from a URL to a local folder.

Suppose you have the archive file example.tar.gz stored at the URL http://example.com/example.tar.gz. Download and extract the file to the example folder.

url = 'http://example.com/example.tar.gz';
gunzip(url, 'example');
untar('example/example.tar','example');

Input Arguments

collapse all

Name of tar file to extract from, specified as a character vector. If tarfilename has no extension, MATLAB searches for tarfilename appended with .tgz, .tar.gz, or .tar. If you specify a .tgz or .gz extension, then untar extracts the specified file using gunzip.

You can specify tarfilename as an absolute path, or a path relative to the current folder.

If tarfilename is a URL, then tarfilename must include the protocol type (for example, http://). MATLAB downloads the URL to the temporary folder on your system, and then deletes it the URL on cleanup.

Target folder for the extracted files, specified as a character vector.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?