# DotNetZip Command-Line Tools

The Tools/Utilities downloads for DotNetZip include a pair of tools - Zipit.exe and Unzip.exe - that can be used from the command line to manipulate zip files from within batch scripts, or CMD.exe windows.

## ZipIt.exe

This tool can be used to create ZIP files, or update existing ZIP files, from the command line or from a batch file.

Using the command line tools, you can do virtually everything you can do by using the library directly from a custom application. You can create self-extracting archives or archives that use ZIP64 extensions. You can create archives that use encryption or passwords. You can create split or spanned archives. And there are many other options.

### Usage

    ZipIt.exe <ZipFileToCreate> [arguments]

    arguments:
      <directory> | <file> - a directory or file to add to the archive.
      <selector>           - a file selection expression.  Examples:
                               *.txt
                               (name = *.txt) OR (name = *.xml)
                               (attrs = H) OR (name != *.xml)
                               (ctime < 2009/02/28-10:20:00)
                               (size > 1g) AND (mtime < 2009-06-29)
                               (ctime > 2009-04-29) AND (size < 10kb)
                             Filenames can include full paths. You must surround a filename
                             that includes spaces with single quotes.
      -64                  - use ZIP64 extensions, for large files or large numbers of files.
      -aes                 - use WinZip-compatible AES 256-bit encryption for entries
                             subsequently added to the archive. Requires a password.
      -cp <codepage>       - use the specified numeric codepage for entries with comments
                             or filenames that cannot be encoded with the default IBM437
                             code page.
      -d <path>            - use the given directory path in the archive for
                             succeeding items added to the archive.
      -D <path>            - find files in the given directory on disk.
      -e<s,r,q,a>          - when there is an error reading a file to be zipped, either skip
                             the file, retry, quit, or ask the user what to do.
      -j-                  - do not traverse NTFS junctions
      -j+                  - traverse NTFS junctions (default)
      -L <level>           - compression level, 0..9 (Default is 6).
      -p <password>        - apply the specified password for all succeeding files added.
                             use "" to reset the password to nil.
      -progress            - emit progress reports (good when creating large zips)
      -r-                  - don't recurse directories (default).
      -r+                  - recurse directories.
      -s <entry> 'string'  - insert an entry of the given name into the
                             archive, with the given string as its content.
      -sfx [w|c]           - create a self-extracting archive, either a Windows or console app.
      -split <maxsize>     - produce a split zip, with the specified maximum size.  You can
                             optionally use kb or mb as a suffix to the size.
                             -split is not compatible with -sfx.
                             This is not compatible with -sfx.
      -Tw+                 - store Windows-format extended times (default).
      -Tw-                 - don't store Windows-format extended times.
      -Tu+                 - store Unix-format extended times (default).
      -Tu-                 - don't store Unix-format extended times (default).
      -UTnow               - use uniform date/time, NOW, for all entries.
      -UTnewest            - use uniform date/time, newest entry, for all entries.
      -UToldest            - use uniform date/time, oldest entry, for all entries.
      -UT <datetime>       - use uniform date/time, specified, for all entries.
      -utf8                - use UTF-8 encoding for entries with comments or
                             filenames that cannot be encoded with the default IBM437
                             code page.
      -zc <comment>        - use the given comment for the archive.

### Command Examples

Use this Command... | to do this...
zipit.exe NewZip.zip -64 *.doc
| create a new zip file called NewZip.zip, adding all .doc files from the current directory into the zip. Use ZIP64 extensions.
zipit.exe NewZip.zip -r+ *.doc
| create a new zip file called NewZip.zip, adding all .doc files, in the current directory and any child directories, into the zip.
zipit.exe Backup.zip -d c:\MyDocuments -r+ -j- *.*
| create a new zip file called Backup.zip, adding all files within the c:\MyDocuments directory. Do not traverse NTFS Junction points (like My Videos).
zipit.exe Package.exe -sfx -d c:\files -r+ *.*
| create a new self-extracting archive file called Package.exe, adding all files within the c:\files directory hierarchy.
zipit.exe Package.zip -split 1mb -d c:\files -r+ *.*
| create a new "spanned" or multi-segment zip file called Package.zip, adding all files within the c:\files directory hierarchy. Each segment of the zipfile should be limited to 1mb in size, and the segments will be named Package.z01, Package.z02, etc.
zipit.exe ImageLibrary.zip -split 1mb -d c:\images -r+ "name = *.jpg AND size > 100kb"
| create a new "spanned" or multi-segment zip file called ImageLibrary.zip, adding all .jpg files within the c:\images directory hierarchy that have a size larger than 100kb. Each segment of the zipfile should be limited to 1mb in size, and the segments will be named Package.z01, Package.z02, etc.
zipit.exe Portfolio.zip -p Secret! -aes -d c:\portfolio -r+ "name != *.tfs"
| create a new aip file called Portfolio.zip, adding all files within the c:\portfolio directory hierarchy that do not have the .tfs extension. Encrypt all entries using AES 256-bit encryption.
zipit.exe Portfolio.zip -p Secret! -aes -L 9 -d c:\portfolio -r+ "name != *.tfs"
| create a new aip file called Portfolio.zip, adding all files within the c:\portfolio directory hierarchy that do not have the .tfs extension. Encrypt all entries using AES 256-bit encryption, and use level 9 (Best) compression.

### Syntax for the Selection Criteria

Using the a selector string, you can specify a set of criteria for the files to be added to the zip file. Specify the criteria in statements of 3 elements: a noun, an operator, and a value. Consider the string "name != *.doc" . The noun is "name". The operator is "!=", implying "Not Equal". The value is "*.doc". That criterion, in English, says "all files with a name that does not end in the .doc extension."

Supported nouns include name for the filename; atime, mtime, and ctime for last access time, last modfied time, and created time of the file, respectively; attributes for the file attributes; and size for the file length (uncompressed). The attributes and name nouns both support = and != as operators. The size, atime, mtime, and ctime nouns support = and !=, and >, >=, <, <= as well. The times are taken to be expressed in local time.

Specify values for the file attributes as a string with one or more of the characters H,R,S,A in any order, implying Hidden, ReadOnly, System, and Archive, respectively. To specify a time, use YYYY-MM-DD-HH:mm:ss or YYYY/MM/DD-HH:mm:ss as the format. If you omit the HH:mm:ss portion, it is assumed to be 00:00:00 (midnight). The value for a size criterion is expressed in integer quantities of bytes, kilobytes (use k or kb after the number), megabytes (m or mb), or gigabytes (g or gb). The value for a name is a pattern to match against the filename, potentially including wildcards. The pattern follows CMD.exe glob rules: * implies one or more of any character (not including dot), while ? implies one character (not including dot). If the name pattern contains any slashes, it is matched to the entire filename, including the path; otherwise, it is matched against only the filename without the path. This means a pattern of "*\*.*" matches all files one directory level deep, while a pattern of "*.*" matches all files in all directories.

To specify a name pattern that includes spaces, use single quotes around the pattern. A pattern of "'* *.*'" will match all files that have spaces in the filename. The full criteria string for that would be "name = '* *.*'" .

### Examples of Selection Criteria

Use this Command... | to do this...
name = *.jpg
| any .jpg file
mtime > 2009-07-14
| any file with a last modified time after midnight on 14 July 2009. There is also ctime and atime for created time and accessed time.
ctime > 2009-07-14-07:53:00
| any file with a created time after 7:53am (local time) on 14 July 2009.
size > 320mb
| any file with a size over 320mb. You can use kb or gb, too. Or omit the characters to specify a filesize in bytes. And you can use <, >, or = as operations.
attr != H
| any file that does not have the Hidden attribute set. Other attributes include S=system, R=Readonly, A=Archive. Of course you can test that the attribute is ON as well, using = instead of !=.
attr != H and size > 320mb
| include the files that satisfy both conditions. You can also use OR as a conjuction. Use parens to group complex expressions.
name = *.jpg or name = *.gif
| include the files that satisfy one or the other condition.
(name = *.jpg) or (name = *.gif)
| same as above.
(mtime >= 2009-07-01) and (mtime < 2009-07-02)
| any file modified on July 1st. From midnight to midnight.
(name = *.jpg) AND (mtime >= 2009/07/01) and (mtime < 2009/07/02)
| any .jpg file modified on July 1st.
(name = *.jpg) and (size >= 100kb) and (mtime >= 2009/07/01) and (mtime < 2009/07/02)
| any .jpg file, 100kb or more in size, modified on July 1st.

## UnZip.exe

This tool can be used to view, extract, or test and verify ZIP files, from the command line or from a batch file.

### Usage

      UnZip.exe [options] <zipfile> [<entryname>...]
         unzips all files in the archive.
         options:
           -o                overwrite existing files if necessary.
           -f                flatten directory structure when extracting.
           -p <password>     specify password for extraction.
           -t                test the file for consistency.
           -q                operate quietly (no verbose messages).
           -cp <codepage>    extract with the specified numeric codepage.  Only do this if you
                             know the codepage, and it is neither IBM437 nor UTF-8. If the
                             codepage you specify here is different than the codepage of
                             the cmd.exe, then the verbose messages will look odd, but the
                             files will be extracted properly.
           -d <directory>    unpack to the specified directory. If none provided, it will
                             unzip to the current directory.
           <entryname>       unzip only the specified filename.

      unzip -l <zipfile>
         lists the entries in the zip archive.
      unzip -i <zipfile>
         displays full information about all the entries in the zip archive.
      unzip -t <zipfile> [-p <password>] [-cp <codepage>]
         tests the zip archive.
      unzip -?
         displays this message.

### Command Examples

Use this Command... | to do this...
UnZip.exe -l Package.zip
| list the entries in the zipfile, along with basic information about each entry.
UnZip.exe Package.zip
| extract the entries in the zipfile, into the current directory.
UnZip.exe Package.zip -d ex1
| extract the entries in the zipfile, into the directory 'ex1'. The directory will be created if it does not exist.
UnZip.exe Package.zip -f -d ex1
| extract the entries in the zipfile, into the directory 'ex1'. The directory will be created if it does not exist. Any directory hierarchy within the zip file will be ignored or "flattened" upon extraction.
UnZip.exe Package.zip -o -d ex1
| extract the entries in the zipfile, into the directory 'ex1'. The directory will be created if it does not exist. During extraction, any existing files in the directory hierarchy will be overwritten if necessary.