Alex de los Santos
Alex de los Santos

Reputation: 13

How to compress with the default name in 7z?

I have a variable named file called fooDATE.txt when DATE is the variable part.

How to compress this file using command line (in Windows with 7z) so that the compressed file has the same name as the original file? I want it to be called in the same way as the source file.

For example: For the file foo20170302.txt compress to foo20170302.zip

This not work: 7z.exe -tzip C:\foo*.zip C:\foo*.txt

Thank you very much.

Upvotes: 1

Views: 222

Answers (1)

SACn
SACn

Reputation: 1924

In directory where files are present use dos for loop with substitution modifiers. Your case as follows:

for %f in (*.txt) do 7z.exe -tzip "%~nf.zip" "%~nf.txt"

Upvotes: 1

Related Questions