2

Say I have 1 main folder and 10 sub-folders, each with .avi, .html ,.txt and .srt in them.

Now I want to preserve the folder structure but I want to only compress the .srt files into .7zip.

Is there a command for that?

1 Answer 1

6
set path=%path%;C:\Program Files\7-Zip
7z a archive.7z -ir!MainFolder\*.srt

reference:
7z --help or 7z(without parameter)
7-Zip Command Line User's Guide

5
  • where do you get exclamation mark from? I can't see it in the user's guide, though I see it works with it
    – barlop
    Nov 26, 2018 at 1:33
  • here you go
    – guest
    Dec 6, 2018 at 19:57
  • Note, if your MainFolder path has spaces in it, wrap the whole path in quotes, otherwise 7z will just ignore your pattern and compress all the files.
    – Paul Suart
    Jan 21, 2019 at 14:31
  • With 7z.exe a -tzip metadata.zip -ir!.\*.xmp I had "Too short switch/Cannot find file" error/warning. Added quotes to path and went perfect 7z.exe a -tzip metadata.zip -ir!".\*.xmp"
    – quantme
    Apr 8, 2019 at 0:30
  • You can also try zip -r foo /MainFolder -i '*.py' '*.pdf' '*.tex' '*.doc' '*.docx'
    – Darkmoor
    May 29, 2023 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .