Search notes:

7z.exe

7z.exe is the command line (cmd.exe, PowerShell) version of 7-Zip.

Creating a zip file

7z.exe can be used to create a zip file on the command line. When 7z.exe is invoked, it needs the a argument and a list of files. The list of files may include the wildcard *.
The following command adds all files (*) including those of subdirectories (-r = recursively) to a zip file named file.zip. If file.zip does not exist, it will be created.
C:\> 7z.exe a file.zip * -r

Creating a zip file from a select list of files

At times, a zip file needs to be created that contains a subset of files stored in multiple subdirectories. If this list of files cannot be identified by a simple (or complicated) wildcard, instead of using *, each file can be individually specified in the 7z a command.
In the following example, I use the line continuation character (^) to write each file on a separate line to make it visually easier for a human to see what's going on.
del FooBarBaz.zip

"c:\Program Files\7-zip\7z.exe"  a foobarbaz.zip   ^
     README.txt                                    ^
     theData.xlsx                                  ^
     SQLs\schema\create-tables.sql                 ^
     SQLs\schema\create-views.sql                  ^
     VBA\accessBootstrap.vbs                       ^
     VBA\init.bas                                  ^
     VBA\loadModules.bas

Extracting files from a zip file

Files can be extracted from zip file on the command line with the x command:
C:\> 7z.exe x file.zip
Note: there is also an e command. Unlike x, e will not create the files with the directory structure that they were added to the zip file.

Extracting files to an aribtrary directory

The -o flag specifies the target directory into which the archive files are extracted.
There must be no space between -o and the directory path:
C:\Users\Rene\Downloads> "c:\Program Files\7-Zip\7z.exe" x theArchive.7z -oc:\Users\Rene\dest

Specifying destination directory when extracting 7z.exe files

The -o flag can also be used to specify the destination directory when extracting from *.7z.exe files:
C:\Users\Rene\Downloads> .\xyz.7z.exe -o %temp% -y
The -y option prevents asking for confirmation.

Installing 7-Zip

7-Zip can be installed, for example, with Chocolatey, see here.

See also

%PROGRAMFILES%\7-zip

Index