-ai (Include archive filenames) switch
Specifies additional include archive filenames and wildcards.
Multiple include switches are supported.
Syntax
-ai[<recurse_type> ][<mark_type>][<wildcard_type>]<file_ref>
<recurse_type> ::= r[- | 0]
<mark_type> ::= m[- | 2]
<wildcard_type> ::= w[-]
<file_ref> ::= @{listfile} | !{wildcard}
See -i (Include filenames) switch description for information about
-x option parameters.
Parameters
<recurse_type>
Specifies how wildcards and file names in this switch must
be used. If this option is not given, recursion will be not used.
For more details see specification of the
-r (Recurse) switch.
<recurse_type> ::= r[- | 0]
<file_ref>
Specifies filenames and wildcards or list file that specify processed files.
<file_ref> ::= @{listfile} | !{wildcard}
Examples
7z t -an -air!*.7z
tests *.7z archives in current directory and all it's
subdirectories.
Commands that can be used with this switch
e (Extract) ,
l (List) ,
t (Test) ,
x (Extract with full paths)
See also
Switches:
-ax (Exclude archives)
-an (Disable parsing of archive_name)
Notes from this site
Not part of the 7-Zip manual. Written by this site; examples checked with 7-Zip 26.04.
The vendor line "See -i for -x option parameters" means -ai takes the same r, m, w letters and !wildcard or @listfile forms as -i .
How do I test or extract every .7z in a folder?
Use 7z on Windows and 7zz (the official console binary) on Linux/macOS. Quote patterns on Linux/macOS so the shell does not expand * or !. In Windows cmd, single quotes are not quote characters: use the unquoted form, such as 7z x -an -ai!*.7z -o*.
7z t -an -ai!*.7z
7zz t -an -ai'!*.7z'
7zz t -an -air'!*.7z'
7zz x -an -ai'!*.7z' -o'*'
7zz x -an -ai@archives.txt -o'*'
7zz t -an -ai'!*.7z' -ai'!*.zip'
7zz l -an -ai'!*.7z'
7zz t -an -ai'!*.7z' -bso0 -bsp0 || echo FAILED
Lines 1 and 2 test every .7z in the current folder; line 3 adds r to include subfolders.
Lines 4 and 5 extract each archive into a folder named after it. -o* works with e and x only.
Line 5 reads one archive name per line from archives.txt (see list files ); names with spaces are fine, so it is the safest choice in scripts. On Linux/macOS, ls *.7z > archives.txt creates it.
Line 6 covers two formats; line 7 lists the contents of every .7z.
Line 8 is a backup check: it stays silent and prints FAILED if any archive is damaged (exit code 2 in a test). The || form works in cmd too.
What is the difference between -ai and -air?
Plain -ai searches only the current folder (or the path in the pattern, for example -ai'!sub/*.7z'). -air searches subfolders too, with the same rules as -r .
Common mistakes
Forgetting -an : 7-Zip still expects an archive name and stops with "Cannot find archive name".
Using -ai with a command that creates archives; it applies only to e, l, t and x.
Skipping the quotes on Linux/macOS, so the shell expands the pattern first.
Related pages
-an , -ax , -i , -r , t (Test)