从文件名中删除扩展名 [英] Remove extension from filename

查看:46
本文介绍了从文件名中删除扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

folder1 中,我有一个文件列表:

In folder1 I have a list of files:

file1.exe
ahahdf.exe
ahdfkqkq.exe

我想运行一个脚本并让它在文件夹 2 中创建以下文件:

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 files7-zip7z.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).

我该怎么做?

推荐答案

应该是

for %%f in (*.*) do "c:program files7-zip7z.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆