CMD问:我想删除文件名的扩展名。
它实际上是一个完整的路径,如C:/Me/My/Path/filename.xxxx
我知道扩展名有4个字符,如上例所示。
我如何摆脱扩展?
感谢。
答案 0 :(得分:3)
在终端:
set file=C:/Me/My/Path/filename.1234
for /F "tokens=*" %A IN ("%file%") DO @echo variable ^%file^%: %~dpnA
在批处理文件中:
@echo off
set file=C:/Me/My/Path/filename.1234
echo If called with path as batch parameter: %~dpn1
for /F "tokens=*" %%A IN ("%file%") DO echo variable %%file%%: %%~dpnA
答案 1 :(得分:1)
这就是诀窍:
@echo off
set fullpath= C:/Me/My/Path/filename.xxxx
set withoutext=%fullpath:~0,-5%
echo %withoutext%
结果是:
c:\>test
C:/Me/My/Path/filename
在此示例脚本中,最后5个字符将从变量%fullpath%。
中删除此处解释了语法:http://www.computerhope.com/forum/index.php?topic=78901.0
如果扩展名的长度未知,则无效。
答案 2 :(得分:1)
ren C:/Me/My/Path/filename.xxxx filename.
这应该这样做(最后的“。”很重要)