ZIP (.zip)

Background & Context

    • 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 & Export

  • When importing files from a ZIP archive, the specific converter for each format will be used.
  • Import[""] returns an expression of the form {"fn1", "fn2",}, giving full path specifications for all files in "".
  • Import["",elem] imports the specified element from a ZIP file.
  • Import["","fn"] extracts "fn" from the archive and imports it.
  • Import["",{elem,suba,subb,}] imports a subelement.
  • Import["",{{elem1,elem2,}}] imports multiple elements.
  • Import["file","ZIP"] or Import["file",{"ZIP",elem,}] imports any file as a ZIP archive.
  • Export["",expr,elem] creates a ZIP archive by treating expr as specifying element elem.
  • Export["",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["","fn"->expr] exports expr to a file and compresses it as a ZIP archive, inferring the file format from the file extension of "fn".
  • Export["",{"fn1"->expr1,"fn2"->expr2,}] exports multiple expressions to a ZIP file archive.
  • Export["",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.

Import Elements

  • 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 "FileNames" element for the ZIP format.
  • Import["","fn"] extracts and imports file "fn".
  • File names can include relative or absolute directory specifications and the abbreviated string patterns supported by StringMatchQ.
  • Import["","*"] imports an entire archive.
  • Import["","dir/*.jpg"] imports all JPEG files from subdirectory dir.
  • Export["","file1.gif"->expr1,"file2.txt"->expr2] 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.


open allclose all

Basic Examples  (1)

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

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

Import all files using their default element:

Extract and import the GIF file:

Extract and import all text files:

Scope  (1)

Elements for a ZIP archive:

Extract available elements for one of the files in the ZIP archive:

Import some elements from one of the files in the archive:

Import the default element for multiple files with different formats:

Import Elements  (1)

"FileNames"  (1)

Get the names of all files in a ZIP archive:

This is also the default element:

Introduced in 2007
Updated in 2017