How Do I Recursively Compress Only Certain File Extensions with 7Zip Command Line?

With what commands can I compress only certain file extensions with 7zip? e.g. *.txt and *.doc and *.docx (across subdirectories, so 'recursively')

I read Compress only specific files from a folder while preserving folder structure and from there I can see that 7z a archive.7z -ir!.\*.txt would compress all txt files in the current directory, but what if I want to specify multiple extensions e.g. *.txt, *.doc and *.docx?

1 Answer

You can repeat the -ir switch several times, like

 7z a archive.7z -ir!.\*.txt -ir!.\*.doc

(sometimes, just trying things out is the fastest way to get an answer ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest