Like this it work:
Put this in your working directory and run it.
@echo off
setlocal EnableDelayedExpansion
for /d %%a in (*) do (
for /f "delims=" %%F in ('dir /s/b/a-d/on "%%a"') do set $last="%%~nF%%~xF"
echo last of %%a is !$last!
)
echo Done...
pause
Edit :
To make your code working :
@echo off
setlocal EnableDelayedExpansion
for /D %%G in (*) do (
echo %%G
cd %%G\
for /f "delims=" %%F in ('dir/b/a-d/on') do (
set last=%%F
)
echo !last!
cd..
pause
)
cd..
cd..