How to Use List Files in 7-Zip CLI
This article explains how to use response files—referred to as list files in 7-Zip—to pass multiple file and directory parameters to the 7-Zip Command Line Interface (CLI). Using list files allows you to bypass operating system command-line length limitations and automate batch archiving or extraction tasks by referencing external text files.
What Is a List File in 7-Zip?
A list file is a standard plain text file containing a list of file paths, directory paths, or wildcards separated by newlines. When executing commands, 7-Zip reads the contents of this file and processes each line as an individual argument.
To tell 7-Zip that a parameter refers to a list file rather than a
literal file name, prefix the list file's path with the @
symbol:
@listfile.txtCreating the List File
- Create a new text file using any standard text editor (such as Notepad or Vim).
- Add each file path, folder path, or wildcard pattern on a separate line.
- Save the file. For paths containing non-ASCII or Unicode characters, save the file using UTF-8 encoding.
Example filelist.txt:
C:\Data\Report.pdf
C:\Data\Images\*.png
"C:\Program Files\App\config.json"
subfolder\notes.txt
Note: While quotes around paths with spaces are generally accepted, standard newline separation in a list file typically allows 7-Zip to handle spaces without explicit quotes.
Archiving Files Using a List File
To compress items specified in a list file, append the @
flag followed by the path to your text file to the a (add)
command:
7z a backup.7z @filelist.txtIf the list file is stored in a different directory, provide its relative or absolute path:
7z a backup.7z @"C:\Scripts\filelist.txt"Excluding Files Using a List File
You can also use list files to exclude specific files or directories
from an archive operation using the -x (exclude)
switch:
7z a backup.7z C:\Data\* -xr@exclude_list.txtIn this command:
-xtriggers exclusion.rapplies the exclusion recursively across subdirectories.@exclude_list.txtspecifies the file containing the patterns to ignore.
Extracting Specific Files Using a List File
To extract only a specific subset of files from an existing archive,
pass the list file to the e (extract) or x
(extract with full paths) command:
7z x backup.7z @restore_files.txt -o"C:\RestoredData"7-Zip will search the archive and extract only the items matching the
entries in restore_files.txt.