-->

卸下文件扩展名(Remove extension from filename)

2019-10-29 03:55发布

folder1我有文件的列表:

file1.exe
ahahdf.exe
ahdfkqkq.exe

我想运行一个脚本,并使其创建文件夹2下列文件:

file1.zip
ahahdf.zip
ahdfkqkq.zip

我尝试:

for %%f in (*.*) do "c:\program files\7-zip\7z.exe" a %%f.zip %%f

这将创建file1.exe.zip ,......但我需要file1.zip ,...(不.exe扩展名)。

我怎样才能做到这一点?

Answer 1:

应该

for %%f in (*.*) do "c:\program files\7-zip\7z.exe" a %%~nf.zip %%f

注意%%~nf - ~n告诉命令解释器挑不带扩展名的文件名部分。

此外,我会附上参数为双引号(“参数”),以确保包含空格的文件名妥善处理。



文章来源: Remove extension from filename