Get filename from string-path?

ajax333221 picture ajax333221 · May 1, 2012 · Viewed 59k times · Source

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)

Answer

dbenham picture dbenham · May 1, 2012

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.