中国DOS联盟论坛

中国DOS联盟

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

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

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 请问如何从路径中提取文件名?
作者:
标题: 请问如何从路径中提取文件名? 上一主题 | 下一主题
3dnowex
初级用户





积分 41
发帖 20
注册 2007-3-5
状态 离线
『楼 主』:  请问如何从路径中提取文件名?

请问如何从路径中提取文件名? 例如 F:\md\abc\sdf.exe 文件名为 sdf.exe 请问如何提取? 谢谢!


2008-7-4 11:29
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
balinger
中级用户




积分 356
发帖 115
注册 2004-7-27
状态 离线
『第 2 楼』:  

for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi


2008-7-4 12:23
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
HAT
版主





积分 9023
发帖 5017
注册 2007-5-31
状态 离线
『第 3 楼』:  

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




2008-7-4 12:36
查看资料  发短消息 网志   编辑帖子  回复  引用回复
54cml
新手上路





积分 16
发帖 7
注册 2008-4-29
状态 离线
『第 4 楼』:  

Originally posted by balinger at 2008-7-4 12:23: for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi
如果路径中有空格就会出错,请问怎么解决?


2009-1-22 18:55
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
netbenton
银牌会员

批处理编程迷


积分 1916
发帖 752
注册 2008-12-28
来自 广西
状态 离线
『第 5 楼』:  

for /f "tokens=*" %%i in (F:\md\abc\sdf.exe") do echo %%~nxi 这样就不怕空格了




精简 [你的+我的+他的]=>[大家的] 个人网志
2009-1-22 20:20
查看资料  发送邮件  发短消息 网志  OICQ (37659560)  编辑帖子  回复  引用回复
zhengqian529
初级用户





积分 100
发帖 93
注册 2009-1-14
来自 湖南
状态 离线
『第 6 楼』:  

都已经解决了。来晚一步


2009-1-23 11:29
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (250988158)  编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: