Q:

Nested for loop - batch Script

Hello Batch File experts,
I wrote this piece of code which will print the Latest file version present in the folder in comparison to file name sent as argument, however these line seems to work accordingly when I remove the outer for loop, which I designed to loop as many time as CLI arguments. 
FOR /f %%f IN ('DIR /b %%a.*.zip') DO @SET last=%%f
ECHO %last%

Full code : 
cd C:\Users\batch\Desktop\test
chdir

set arg1=%1
set arg2=%2
set list=%arg1% %arg2%

(for %%a in (%list%) do (

FOR /f %%f IN ('DIR /b %%a.*.zip') DO @SET last=%%f

ECHO %last%

)) 

pause

what am I missing here because of which variable last is not set with value when outer loop is present which works perfectly without it.
Thanks,

A:

Might I suggest you use SHIFT instead:
@Echo Off
SetLocal
If %1'==' Exit/B
If /I Not "%CD%"=="%USERPROFILE%\Desktop\test" (
    PushD "%USERPROFILE%\Desktop\test" 2>Nul&&(Set _=PopD)||Exit/B)
:Loop
For %%A In ("%~1*.zip") Do Set "last=%%A"
Echo=%last%
Shift
If Not %1'==' GoTo Loop
%_%
EndLocal
Timeout -1

This of course means that you are free to use it with more than two arguments!

