Get filename from string-path?

Assuming you need the the names of files under the "c:\temp" directory tree (including sub-directories):

FOR /R c:\temp %i in (*.*) do echo %~nxi

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


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.