CreateArchive

CreateArchive[source]

creates a compressed archive in the current directory from 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", ".tgz" and ".zst".
  • The source specification can be any of the following:
  • File["source"] or "source"explicit file name or a directory
    URL["url"] or "url"HTTP, HTTPS or FTP URL
    {source1,source2,}a list of files or directories
    <|"file1"source1,"file2"source2,|>rename each file or directory to filen
  • By default, CreateArchive creates an archive in the current working directory given by 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 path specifies a directory, a suitable file name for the archive is automatically chosen.
  • CreateArchive returns the full file name of the archive it created, and $Failed if it cannot be created.
  • The following options can be given:
  • CompressionLevelAutomaticthe compression level to use
    CreateIntermediateDirectoriesTruewhether to create intermediate directories
    OverwriteTargetFalsewhether to overwrite an existing archive
  • Possible settings for OverwriteTarget include:
  • Falsedo not overwrite an existing file
    Trueoverwrite an existing file
    "KeepBoth"keep the existing file, automatically choosing a name for the new file
  • CreateArchive with URL sources accepts the following URLDownload options:
  • AuthenticationNoneauthentication information to send
    CookieFunctionAutomaticfunction to apply to each cookie received
    ConnectionSettingsAutomaticspeed and other settings for the connection
    FollowRedirectsTruewhether to follow HTTP redirects
    InteractiveTruewhether to allow interactive authentication dialogs
    TimeConstraintInfinitytime to wait for a response
    VerifySecurityCertificatesTruewhether to verify SSL security certificates
  • CreateArchive does not delete the source files or directories.

Examples

open allclose all

Basic Examples  (3)

Create a ZIP archive from the ExampleData directory:

Delete the resulting archive:

Create a ZIP file from a list of files from the ExampleData directory:

Import the list of file names included in the ZIP file:

Delete the resulting archive:

Specify an explicit destination directory:

Delete the resulting archive:

Scope  (11)

Source  (5)

Create a ZIP archive from a single file:

Delete the resulting archive:

Create a ZIP archive from a directory:

Delete the resulting archive:

Gather a list of files to archive:

Create a ZIP archive from the chosen files:

Delete the resulting archive:

Specify names for each file or directory inside the archive:

Import the list of file names included in the ZIP file:

Delete the resulting archive:

Create a ZIP archive using both remote and local files:

Import the list of file names included in the ZIP file:

Delete the resulting archive:

Path  (3)

If no destination is specified, the archive is placed in the path given by Directory[]:

Delete the resulting archive:

Specify an explicit destination directory:

Delete the resulting archive:

Specify an explicit archive name:

Delete the resulting archive:

Format  (3)

By default, a ZIP file is created:

Delete the resulting archive:

If a destination is specified, the archive format is inferred from the extension of the destination.

Create a .gz file:

Delete the resulting archive:

Create an explicitly named .tar.bz2 archive in a specific directory:

Delete the resulting archive:

Options  (4)

CompressionLevel  (1)

Check file size before compression:

Some compression is performed by default:

Delete the resulting archives:

Specify that no compression should be used:

Delete the resulting archives:

Specify that maximal compression should be used:

Delete the resulting archive:

CreateIntermediateDirectories  (2)

Prevent creation of intermediate directories to the destination path:

Intermediate directories are created on the destination path by default:

Delete the created directory:

OverwriteTarget  (1)

Create a GZIP compressed file:

Files are not overwritten by default:

Use OverwriteTargetTrue to overwrite existing files:

Delete the resulting archive:

Applications  (1)

Use SendMail to send a directory with maximal file compression:

Delete the resulting archive:

Properties & Relations  (1)

CreateArchive constructs an archive from files and directories already on the file system:

Export can be used to create an archive from expressions in the Wolfram Language:

Delete the resulting archives:

Possible Issues  (1)

GZIP and BZIP2 only support compression of a single file:

Wolfram Research (2010), CreateArchive, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateArchive.html (updated 2020).

Text

Wolfram Research (2010), CreateArchive, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateArchive.html (updated 2020).

BibTeX

@misc{reference.wolfram_2021_createarchive, author="Wolfram Research", title="{CreateArchive}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/CreateArchive.html}", note=[Accessed: 17-June-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_createarchive, organization={Wolfram Research}, title={CreateArchive}, year={2020}, url={https://reference.wolfram.com/language/ref/CreateArchive.html}, note=[Accessed: 17-June-2021 ]}

CMS

Wolfram Language. 2010. "CreateArchive." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/CreateArchive.html.

APA

Wolfram Language. (2010). CreateArchive. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CreateArchive.html