[英]Get filename from string-path?
我如何从这个字符串中获取文件名?
"C:\Documents and Settings\Usuario\Escritorio\hello\test.txt"
输出:
"test.txt"
我真的试图在发布之前找到这个,但所有结果都被污染了,他们谈论从当前目录获取文件名(我必须只使用字符串)
方法一
for %%F in ("C:\Documents and Settings\Usuario\Escritorio\hello\test.txt") do echo %%~nxF
输入HELP FOR
了解更多信息。
方法二
call :sub "C:\Documents and Settings\Usuario\Escritorio\hello\test.txt"
exit /b
:sub
echo %~nx1
exit /b
输入HELP CALL
了解更多信息。
如果您的路径作为参数出现,只需使用:
%~nx1
(1 是第一个参数,我们假设它是第一个)
echo %~nx1
会直接返回 test.txt
假设您需要“c:\\temp”目录树(包括子目录)下的文件名:
FOR /R c:\temp %i in (*.*) do echo %~nxi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.