Board logo

标题: 请问如何从路径中提取文件名? [打印本页]

作者: 3dnowex     时间: 2008-7-4 11:29    标题: 请问如何从路径中提取文件名?
请问如何从路径中提取文件名?
例如 F:\md\abc\sdf.exe
文件名为 sdf.exe
请问如何提取?
谢谢!

作者: balinger     时间: 2008-7-4 12:23
for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi

作者: HAT     时间: 2008-7-4 12:36
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

作者: 54cml     时间: 2009-1-22 18:55
Originally posted by balinger at 2008-7-4 12:23:
for /f %%i in ("F:\md\abc\sdf.exe") do echo %%~nxi

如果路径中有空格就会出错,请问怎么解决?

作者: netbenton     时间: 2009-1-22 20:20
for /f "tokens=*" %%i in (F:\md\abc\sdf.exe") do echo %%~nxi
这样就不怕空格了

作者: zhengqian529     时间: 2009-1-23 11:29
都已经解决了。来晚一步