中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-08-11 06:35
47,811 主题排行 / 349,897 发帖 / 今日 0 篇 / 48,256 会员排行
DOS批处理 & 脚本技术(批处理室) » 请问如何从路径中提取文件名?
可打印版本  1,060 / 5
第1楼 3dnowex 发表于 2008-07-04 11:29
初级用户 发帖 20 积分 41
请问如何从路径中提取文件名?
请问如何从路径中提取文件名?
例如 F:\md\abc\sdf.exe
文件名为 sdf.exe
请问如何提取?
谢谢!
第2楼 balinger 发表于 2008-07-04 12:23
中级用户 发帖 115 积分 356
for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi
第3楼 HAT 发表于 2008-07-04 12:36
版主 发帖 5,017 积分 9,023
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楼 54cml 发表于 2009-01-22 18:55
新手上路 发帖 7 积分 16
Originally posted by balinger at 2008-7-4 12:23:
for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi

如果路径中有空格就会出错,请问怎么解决?
第5楼 netbenton 发表于 2009-01-22 20:20
银牌会员 发帖 752 积分 1,916 来自 广西
for /f "tokens=*" %%i in (F:\md\abc\sdf.exe") do echo %%~nxi
这样就不怕空格了
第6楼 zhengqian529 发表于 2009-01-23 11:29
初级用户 发帖 93 积分 100 来自 湖南
都已经解决了。来晚一步
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023