-w (set Working directory) switch
Sets the working directory for the temporary base archive. By
default, 7-Zip builds a new base archive file in the same directory as the
old base archive file. By specifying this switch, you can set the
working directory where the temporary base archive file will be built.
After the temporary base archive file is built, it is copied over the
original archive; then, the temporary file is deleted.
Syntax
-w[{dir_path} ]
{dir_path}
Specifies the destination directory path. It's not required that
a path end with a backslash.
If <dir_path> is not assigned, then 7-Zip will use the Windows temporary directory.
Example
7z a -tzip archive.zip *.cpp -wc:\temp
adds *.cpp files to the
archive.zip archive, creating a temporary archive
in c:\temp folder.
Commands that can be used with this switch
a (Add) ,
d (Delete) ,
rn (Rename) ,
u (Update) ,
Notes from this site
Not part of the 7-Zip manual. Written by this site; examples checked with 7-Zip 26.04.
How do I use another disk for temporary files?
On Linux and macOS the official console binary is 7zz; on Windows it is 7z. Write the path directly after -w, with no space.
7zz a -tzip archive.zip *.cpp -w/tmp/work
7zz u /mnt/share/backup.7z data/ -w/tmp/work
7zz d backup.7z '*.tmp' -r -w/tmp/work
7z u E:\backup.7z C:\data\* -wD:\temp
Typical use: the archive lives on a slow network share, a full drive or a small disk, and you point -w at a fast, roomy local disk. The temporary file is built there and copied over the archive at the end, so the -w folder needs free space for the whole new archive. The path may be absolute or relative to the current directory. While 7-Zip works, the temporary file is named after the archive (archive.zip.tmp). In 7-Zip 26.04, a uses the -w folder when it creates a new archive too (we saw n.7z.tmp there during a run).
What does a bare -w do?
Without a path, the vendor text says 7-Zip uses the Windows temporary directory. With 7zz 26.04 on macOS, 7zz a t.7z a.txt -w created the archive with exit code 0; we did not check which folder it used for the temporary file, and the manual says nothing about Linux or macOS, so give an explicit path.
Is -w the same as the output folder -o?
No. -w only moves the temporary archive for a, u, d and rn. The final archive stays where you named it; extracted files go where -o says.
Common mistakes
Putting a space before the path: -w work is read as a bare -w, and work is added to the archive as a file or folder (with 7zz 26.04 on macOS: exit code 0 when the folder existed, and exit code 1 with the warning "errno=2 : No such file or directory" when it did not).
Pointing -w at a folder that does not exist (-wnodir): 7-Zip stops with "errno=2 : No such file or directory", creates no archive and exits with code 2 (see exit codes ). Create the folder first.
Related pages