Search code examples
extract7zip

7zip commandline extract excluding single file with spaces in the file name


Using 7z.exe (v19.00 x64) from the commandline on Windows 11

I've tried these syntaxes:

"C:\Program Files\7-Zip\7z" x -bb3 -x"Www.WebAddress.Net - My Website.url" -o_Extracted -psomething "ZippedFile (pwd something).zip"

Yields error:

Incorrect wildcard type marker


"C:\Program Files\7-Zip\7z" x -bb3 -xWww.WebAddress.Net - My Website.url -psomething -o_Extracted "ZippedFile (pwd something).zip"

Yields error:

Unknown switch


"C:\Program Files\7-Zip\7z" x -bb3 -x@exclude-list -psomething -o_Extracted "ZippedFile (pwd something).zip"

Contents of exclude-list:

Www.WebAddress.Net - My Website.url
Www.WebAddress.Net - My Website.*
Www.WebAddress.Net - My Website
*.url

This works but DOES NOT exclude the file Www.WebAddress.Net - My Website.url from extraction.


Solution

  • To exclude a single file, as per the example:

    "C:\Program Files\7-Zip\7z" x -bb3 -x!"Www.WebAddress.Net - My Website.url" -psomething -o_Extracted "ZippedFile (pwd something).zip"
    

    Use the -x switch and enclose the filename withing double-quotes.

    To exclude a single file recursively:

    "C:\Program Files\7-Zip\7z" x -bb3 -xr!"Www.WebAddress.Net - My Website.url" -psomething -o_Extracted "ZippedFile (pwd something).zip"
    

    To exclude all .url files recursively:

    "C:\Program Files\7-Zip\7z" x -bb3 -xr!*.url -psomething -o_Extracted "ZippedFile (pwd something).zip"
    

    To exclude the list of files contained within the text file -x@exclude-list :

    "C:\Program Files\7-Zip\7z" x -bb3 -x@exclude-list -psomething -o_Extracted "ZippedFile (pwd something).zip"