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.
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 LocalObject[…] a local object CloudObject[…] a cloud object - 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:
-
CompressionLevel Automatic the compression level to use CreateIntermediateDirectories True whether to create intermediate directories OverwriteTarget False whether to overwrite an existing archive - Possible settings for OverwriteTarget include:
-
False do not overwrite an existing file True overwrite 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:
-
Authentication None authentication information to send CookieFunction Automatic function to apply to each cookie received ConnectionSettings Automatic speed and other settings for the connection FollowRedirects True whether to follow HTTP redirects Interactive True whether to allow interactive authentication dialogs TimeConstraint Infinity time to wait for a response VerifySecurityCertificates True whether to verify SSL security certificates - CreateArchive does not delete the source files or directories.
Examples
open all close allBasic Examples (3)
Create a ZIP archive from the ExampleData directory:
archive = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}]]DeleteFile[archive]Create a ZIP file from a list of files from the ExampleData directory:
archive = CreateArchive[FileNames["*.jpg", FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}]]]Import the list of file names included in the ZIP file:
Import[archive]DeleteFile[archive]Specify an explicit destination directory:
archive = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}]]DeleteFile[archive]Scope (12)
Source (6)
Create a ZIP archive from a single file:
file = FindFile["ExampleData/coneflower.jpg"];archive = CreateArchive[file]DeleteFile[archive]Create a ZIP archive from a directory:
archive = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}]]DeleteFile[archive]Gather a list of files to archive:
files = FileNames["*.jpg", FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}]]Create a ZIP archive from the chosen files:
archive = CreateArchive[files]DeleteFile[archive]Specify names for each file or directory inside the archive:
files = FileNames["*.jpg", FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}]];archive = CreateArchive[Association@MapIndexed[ToString@#2[[1]] <> ".jpg" -> #1&, files]]Import the list of file names included in the ZIP file:
Import[archive]DeleteFile[archive]Create a ZIP archive using both remote and local files:
archive = CreateArchive[{FindFile["ExampleData/coneflower.jpg"], URL["http://exampledata.wolfram.com/sample.pdf"]}]Import the list of file names included in the ZIP file:
Import[archive]DeleteFile[archive]Create a ZIP archive using a CloudObject that contains an image file:
co = CloudObject["https://www.wolframcloud.com/obj/documentation/flower2"];
Import[co]
CreateArchive[co]Import the list of file names included in the ZIP file:
Import[%]DeleteFile[%%]Path (3)
If no destination is specified, the archive is placed in the path given by Directory[]:
archive = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}]]DeleteFile[archive]Specify an explicit destination directory:
archive = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}], $UserBaseDirectory]DeleteFile[archive]Specify an explicit archive name:
archive = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}], FileNameJoin[{$UserBaseDirectory, "file.zip"}]]DeleteFile[archive]Format (3)
By default, a ZIP file is created:
archive = CreateArchive[FindFile["ExampleData/coneflower.jpg"]]DeleteFile[archive]If a destination is specified, the archive format is inferred from the extension of the destination.
archive = CreateArchive[FindFile["ExampleData/coneflower.jpg"], "coneflower.jpg.gz"]DeleteFile[archive]Create an explicitly named .tar.bz2 archive in a specific directory:
archive = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}] , FileNameJoin[{$UserBaseDirectory, "archive.tar.bz2"}]]DeleteFile[archive]Options (4)
CompressionLevel (1)
Check file size before compression:
FileByteCount[file = FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "coneflower.jpg"}]]Some compression is performed by default:
FileByteCount[archive = CreateArchive[file]]Delete the resulting archives:
DeleteFile[archive]Specify that no compression should be used:
FileByteCount[archive = CreateArchive[file, "CompressionLevel" -> 0]]Delete the resulting archives:
DeleteFile[archive]Specify that maximal compression should be used:
FileByteCount[archive = CreateArchive[file, "CompressionLevel" -> 1]]DeleteFile[archive]CreateIntermediateDirectories (2)
Prevent creation of intermediate directories to the destination path:
CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}],
FileNameJoin[{$HomeDirectory, CreateUUID[], "non", "existent", "directory"}], CreateIntermediateDirectories -> False]Intermediate directories are created on the destination path by default:
CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}],
FileNameJoin[{$HomeDirectory, uniqueDir = CreateUUID[], "non", "existent", "directory"}]]DeleteDirectory[FileNameJoin[{$HomeDirectory, uniqueDir}], DeleteContents -> True]OverwriteTarget (1)
Create a GZIP compressed file:
file = CreateArchive[FindFile["ExampleData/turtle.jpg"], "file.gz"]Files are not overwritten by default:
CreateArchive[FindFile["ExampleData/turtle.jpg"], "file.gz"]Use OverwriteTargetTrue to overwrite existing files:
CreateArchive[FindFile["ExampleData/turtle.jpg"], "file.gz", OverwriteTarget -> True]DeleteFile[file]Applications (1)
Email a Compressed Directory (1)
Use SendMail to send a directory with maximal file compression:
file = CreateArchive[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData"}], CompressionLevel -> 1, OverwriteTarget -> True];SendMail[<|"Subject" -> "Wolfram Guide Pages", "Body" -> "Here's a zip archive of the Wolfram guide pages.", "AttachedFiles" -> file|>]DeleteFile[file]Properties & Relations (1)
CreateArchive constructs an archive from files and directories already on the file system:
archive1 = CreateArchive[FindFile["ExampleData/turtle.jpg"]]Export can be used to create an archive from expressions in the Wolfram Language:
archive2 = Export["test.zip", <|"a.gif" -> \!\(\*GraphicsBox[«4»]\), "b.txt" -> "earth seen from space"|>, "Rules" ]Delete the resulting archives:
DeleteFile[{archive1, archive2}]Related Guides
History
Introduced in 2010 (8.0) | Updated in 2017 (11.1) ▪ 2020 (12.1) ▪ 2020 (12.2) ▪ 2026 (15.0)
Text
Wolfram Research (2010), CreateArchive, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateArchive.html (updated 2026).
CMS
Wolfram Language. 2010. "CreateArchive." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. 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
BibTeX
@misc{reference.wolfram_2026_createarchive, author="Wolfram Research", title="{CreateArchive}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/CreateArchive.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_createarchive, organization={Wolfram Research}, title={CreateArchive}, year={2026}, url={https://reference.wolfram.com/language/ref/CreateArchive.html}, note=[Accessed: 13-June-2026]}