How do I get the filename from this string?
"C:\Documents and Settings\Usuario\Escritorio\hello\test.txt"
output:
"test.txt"
I really tried to find this one before posting, but all the results were contaminated, they talk about getting filenames from current dir (I must work with strings only)
Method 1
for %%F in ("C:\Documents and Settings\Usuario\Escritorio\hello\test.txt") do echo %%~nxF
Type HELP FOR
for more info.
Method 2
call :sub "C:\Documents and Settings\Usuario\Escritorio\hello\test.txt"
exit /b
:sub
echo %~nx1
exit /b
Type HELP CALL
for more info.
if your path comes as a parameter, just use:
%~nx1
(1 is for the first param and we suppose it's the first one)
echo %~nx1
would return directly test.txt
假设您需要“c:\\temp”目录树(包括子目录)下的文件名:
FOR /R c:\temp %i in (*.*) do echo %~nxi
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.