ZIP (.zip)

Registered MIME type: application/zip
Popular data compression and archival format.
Used to reduce storage space and transfer times.
Binary format.
Can contain multiple files.
Supports a variety of compression methods.
Published by Phil Katz in 1989.
  • Import and Export fully support the ZIP format.
  • Import and Export can work with general ZIP archives as well as with specific application formats consisting of multiple related files.

Import and ExportImport and Export

  • When importing from a ZIP archive that constitutes a supported multi-file Import format, the converter for this format will be used.
  • Import["file.zip"] gives full path specifications for all files in a general ZIP file.
  • Export["file.zip", "fn"->expr] exports expr to a file and compresses it as a ZIP archive, inferring the file format from the file extension of .
  • Export["file.zip", {"fn1"->expr1, "fn2"->expr2, ...}] exports multiple expressions to a ZIP file archive.
  • Import["file.zip"] returns an expression of the form .
  • Import["file.zip", "fn"] extracts from the archive and imports it.
  • Import["file.zip", elem] imports the specified element from a ZIP file.
  • Import["file.zip", {elem, suba, subb, ...}] imports a subelement.
  • Import["file.zip", {{elem1, elem2, ...}}] imports multiple elements.
  • Import["file", "ZIP"] or Import["file", {"ZIP", elem, ...}] imports any file as a ZIP archive.
  • Export["file.zip", expr, elem] creates a ZIP archive by treating expr as specifying element elem.
  • Export["file.zip", {expr1, expr2, ...}, {{elem1, elem2, ...}}] treats each as specifying the corresponding .
  • Export["file.zip", expr, opt1->val1, ...] exports expr with the specified option elements taken to have the specified values.
  • Export["file.zip", {elem1->expr1, elem2->expr2, ...}, "Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support ZIP compression.

ElementsElements

  • General Import elements:
  • "Elements"list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • The following can be used to select or specify individual files in a ZIP archive:
  • "FileNames"list of filenames representing the contents of a ZIP archive
    "filename"a single file
    "filename","format" a single file, taken to be in the specified format
    "filename","format",elemelement elem from the specified file
  • Import by default uses the element for the ZIP format.
  • Import["file.zip", "fn"] extracts and imports file .
  • File names can include relative or absolute directory specifications and the abbreviated string patterns supported by StringMatchQ.
  • Import["file.zip", "*"] imports an entire archive.
  • Import["file.zip", "dir/*.jpg"] imports all JPEG files from subdirectory dir.
  • Export["file.zip", {"file1.gif"->"expr1", "file2.txt"->"expr2"}, "Rules"] creates a ZIP archive containing a GIF and a Text file.
  • Export["file", {expr1, expr2}, {"ZIP", {{"file1", "GIF"}, {"file2", "Text"}}}] is equivalent to the above.

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

This creates a ZIP archive containing a GIF and a text file:

In[1]:=
Click for copyable input

Importing a ZIP archive gives the names of the files in the archive:

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

Extract and import "a.gif" from this ZIP file:

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

Extract and import "b.txt" from the file:

In[4]:=
Click for copyable input
Out[4]=
New in 6
New to Mathematica? Find your learning path »
Have a question? Ask support »