[英]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.