如何使用 7z 中的默认名称进行压缩?

How to compress with the default name in 7z?

我有一个名为 fooDATE.txt 的变量,其中 DATE 是变量部分。

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.

例如: 对于文件 foo20170302.txt 压缩到 foo20170302.zip

这不起作用: 7z.exe -tzip C:\foo*.zip C:\foo*.txt

非常感谢。

在存在文件的目录中使用 substitution modifiers 的 dos for 循环。您的情况如下:

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