从文件名中删除扩展名 [英] Remove extension from filename
本文介绍了从文件名中删除扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 folder1
中,我有一个文件列表:
In folder1
I have a list of files:
file1.exe
ahahdf.exe
ahdfkqkq.exe
我要运行脚本并使其在folder2中创建以下文件:
I want to run a script and have it create the following files in folder2:
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
扩展名)。
This creates file1.exe.zip
, ... but I need file1.zip
, ... (without the .exe
extension).
我该怎么做?
推荐答案
应该是
在(*。*)中用于%% f,请执行 c:\程序文件\7-zip\7z.exe a %%〜nf.zip %% f
注意 %%〜nf
-〜n
告诉命令解释器选择不带扩展名的文件名部分。
Note %%~nf
- ~n
tells command interpreter to pick the filename part without extension.
我还将参数括在双引号( param)中,以确保正确处理包含空格的文件名。
Also I would enclose parameters into double-quotes ("param") to ensure that filenames that contain spaces are properly handled.
这篇关于从文件名中删除扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文