中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-11 05:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 请问如何从路径中提取文件名? 查看 1,058 回复 5
楼 主 请问如何从路径中提取文件名? 发表于 2008-07-04 11:29 ·  中国 江西 吉安 电信
初级用户
积分 41
发帖 20
注册 2007-03-05 00:45
19年会员
UID 80788
性别 男
状态 离线
请问如何从路径中提取文件名?
例如 F:\md\abc\sdf.exe
文件名为 sdf.exe
请问如何提取?
谢谢!
2 发表于 2008-07-04 12:23 ·  中国 福建 福州 连江县 电信
中级用户
★★
积分 356
发帖 115
注册 2004-07-27 00:00
22年会员
UID 29114
性别 男
状态 离线
for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi
3 发表于 2008-07-04 12:36 ·  美国 惠普HP
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
for /?
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
4 发表于 2009-01-22 18:55 ·  中国 广西 北海 电信
新手上路
积分 16
发帖 7
注册 2008-04-29 21:27
18年会员
UID 117317
性别 男
状态 离线
Originally posted by balinger at 2008-7-4 12:23:
for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi

如果路径中有空格就会出错,请问怎么解决?
5 发表于 2009-01-22 20:20 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
积分 1,916
发帖 752
注册 2008-12-28 04:30
17年会员
UID 135147
性别 男
来自 广西
状态 离线
for /f "tokens=*" %%i in (F:\md\abc\sdf.exe") do echo %%~nxi
这样就不怕空格了
精简
=> 个人网志
6 发表于 2009-01-23 11:29 ·  美国 华盛顿州 金 雷德蒙德 Microsoft
初级用户
★★
积分 100
发帖 93
注册 2009-01-14 15:04
17年会员
UID 136661
性别 男
来自 湖南
状态 离线
都已经解决了。来晚一步
论坛跳转: