ExtractArchive

ExtractArchive[file]

expands an archive file, saving its content into the current directory.

ExtractArchive[file,dir]

saves the content of an archive file into directory dir.

ExtractArchive[file,dir,pattern]

extracts only files whose names match pattern.

Details and Options

  • ExtractArchive can be used to extract files from an archive file, and returns the names of the files and directories it created.
  • ExtractArchive supports a variety of file formats, including ZIP, TAR, GZIP, BZIP2, 7z, RAR and ISO.
  • By default, ExtractArchive saves the extracted content in the current working directory given by Directory[].
  • The archive to be extracted can be specified using a relative or absolute file specification.
  • The destination directory can be given as a relative or absolute directory path.
  • By default, if any file in the archive to be extracted already exists, ExtractArchive returns $Failed without creating any directories or files.
  • Directories extracted by ExtractArchive may already exist.
  • The following options can be given:
  • CreateIntermediateDirectoriesTruewhether to create intermediate directories
    IgnoreCaseFalsewhether pattern should be case sensitive
    OverwriteTargetFalsewhether to overwrite existing files
  • Possible settings for OverwriteTarget include:
  • Falseif any file from the archive already exists, do nothing and fail
    Trueoverwrite any existing files
    Automaticonly extract files that do not exist
    "KeepBoth"keep the existing file, automatically choosing a name for the new file
  • ExtractArchive[file] does not delete file.
  • ExtractArchive[File["file"],] and ExtractArchive[file,File["dir"],] are also supported.

Examples

open allclose all

Basic Examples  (2)

Uncompress a GZIP file, storing the result in the current directory:

Delete the resulting files:

Specify the destination directory:

Delete the resulting files:

Scope  (1)

Create an archive from the ExampleData directory:

Extract only JPEG files from the resulting archive:

Delete the resulting files and archive:

Options  (3)

CreateIntermediateDirectories  (2)

By default, intermediate directories are automatically created:

Delete the created directory:

Prevent creation of intermediate directories to the destination path:

IgnoreCase  (0)

By default, ExtractArchive uses case sensitive patterns:

Use IgnoreCase -> True to treat lowercase and uppercase letters as equivalents:

Delete the resulting files and archive:

OverwriteTarget  (1)

Create a ZIP archive:

Extract only the JPEG files from the archive:

Delete the first two extracted files:

By default, ExtractArchive will not extract any contents if any destination files already exist:

Use OverwriteTarget->Automatic to only extract files that do not already exist:

Use OverwriteTarget->True to overwrite any existing files:

Properties & Relations  (1)

CreateArchive creates a zip archive on the file system:

ExtractArchive creates new files with the extracted contents, without reading the file into memory:

Import can be used to import a specific file from an archive directly into Wolfram Language:

Introduced in 2010
 (8.0)
 |
Updated in 2017
 (11.1)
2020
 (12.1)