This is my script. In this case I'm trying to get the last file (when sorted alphabetically) of the directory. Whenever I run it, the last file in the 6th folder is given out in every iteration. What is wrong with this script?
@echo off
cd folder1\folder2
for /D %%G in (*) do (
echo %%G
cd %%G
for /f %%F in ('/b/a-d/on') do (
set last=%%F
)
echo %last%
cd..
pause
)
cd..
cd..