CreateArchive

CreateArchive[source]

creates a compressed archive in the current directory from a file or directory specified by source.

CreateArchive[source,path]

creates a compressed archive in the directory or file specified by path.

Details and Options

  • CreateArchive infers the compression format from the file extension of the archive name. If no extension is given, CreateArchive uses ZIP compression.
  • Possible file extensions include ".zip", ".gz", ".tar.gz", ".bz2", ".tar.bz2", ".tbz", ".tbz2", ".tb2", and ".tgz".
  • CreateArchive[source] creates an archive file in the current working directory.
  • The source as well as the destination path can be a relative or absolute directory or file specification.
  • Relative directory or file paths are taken to be relative to the current working directory.
  • If a destination directory is given, CreateArchive automatically chooses a suitable file name for the archive.
  • CreateArchive returns the full file name of the archive it created, and $Failed if it cannot be created.
  • The file archive to be created must not already exist.
  • CreateArchive takes an option CreateIntermediateDirectories to specify whether intermediate directories should be created. The default setting is True.
  • CreateArchive does not delete the source file or directory.
  • CreateArchive[File["source"]] and CreateArchive["Source",File["path"]] are also supported.

Examples

open allclose all

Basic Examples  (4)

Create a ZIP archive from the ExampleData directory and place it into the current directory:

In[1]:=
Click for copyable input
Out[1]=

Create a .tar.gz archive in the current directory:

In[1]:=
Click for copyable input
Out[1]=

Specify an explicit destination path:

In[1]:=
Click for copyable input
Out[1]=

Fully specify a destination path and file name:

In[1]:=
Click for copyable input
Out[1]=

Options  (1)

See Also

ExtractArchive  Compress  Import  Export  FileSystemMap

Introduced in 2010
(8.0)