¿Cómo aprender la última entrada de directorio en la ruta actual?

I am looking for shortest solution for the following problem:

I would like to learn the last directory entry in current path, so for C:\Temp\Local la función debería regresar Lugares

I have come to the following solution but I wonder, if there is more shorter/optimal one:

@echo off

set dir=%CD%

:repeat

for /F "tokens=1,* delims=\" %%a in ("%dir%") do (
    if "%%b" == "" goto :end
    set dir=%%b
)

goto :repeat

:end
echo %dir% 

preguntado el 08 de noviembre de 11 a las 10:11

1 Respuestas

@echo off

for %%* in (.) do @echo %%~n*

respondido 08 nov., 11:17

Could you please explain your solution? %~n is a filename, but what %~n* is? And we need a cycle just to populate %* (e.g. we can't do this trick with %CD%)? - dma_k

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.