Question

I have in a single folder pairs of files with the same filename and different extension.

ex.:

  • filename1.txt
  • filename1.docx
  • filename2.txt
  • filename2.docx
  • filename3.txt
  • filename3.docx
  • filename4.txt
  • filename4.docx
  • etc...

I would like to select all those files and put the pairs in separate zip files.

ex.:

  • filename1.zip (containing "filename1.txt" and "filename1.docx")
  • filename2.zip (containing "filename2.txt" and "filename2.docx")
  • filename3.zip (containing "filename3.txt" and "filename3.docx")
  • filename4.zip (containing "filename4.txt" and "filename4.docx")
  • filename5.zip (containing "filename5.txt" and "filename5.docx")
  • etc...

Is that even possible using 7-zip command line and a prepared batch file?

Was it helpful?

Solution

Double the % to %% for use in a batch file.

FOR %f in (*.txt) DO 7za a "%~nf.zip" "%~nf.txt" "%~nf.docx"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top