I am trying to iterate values using a for-loop but I am not getting expected results. Based on the actual output I think the nested loop is not required here, but I am not sure how can I achieve Expected output without loops.
@Echo Off
SETLOCAL ENABLEDELAYEDEXPANSION
Set "Ids=1,2"
Set "basePath=C:\Users\Documents\ReusableQueries\"
Set "fileName=test1,test2"
Set "extension=.csv"
echo ****Configuation Details****
Echo basePath - %basePath%
Echo fileName - %fileName%
Echo extension - %extension%
echo.
For %%i in (%Ids%) do (
For %%f in (%fileName%) do (
echo Id - %%i and file name - %%f
Set "completepath=%basePath%%%f%extension%"
echo completepath - !completepath!
FOR /F "tokens=*" %%a IN (!completepath!) do (
echo Result of api command1 call for Id : %%i and fileName: %%f
echo.
)
)
)
Pause
Current Output:
****Configuation Details****
basePath - C:\Users\Documents\ReusableQueries\
fileName - test1,test2
extension - .csv
Id - 1 and file name - test1
completepath - C:\Users\Documents\ReusableQueries\test1.csv
Result of api command1 call for Id : 1 and fileName: test1
Id - 1 and file name - test2
completepath - C:\Users\Documents\ReusableQueries\test2.csv
Result of api command1 call for Id : 1 and fileName: test2
Id - 2 and file name - test1
completepath - C:\Users\Documents\ReusableQueries\test1.csv
Result of api command1 call for Id : 2 and fileName: test1
Id - 2 and file name - test2
completepath - C:\Users\Documents\ReusableQueries\test2.csv
Result of api command1 call for Id : 2 and fileName: test2
Expected Output:
****Configuation Details****
basePath - C:\Users\Documents\ReusableQueries\
fileName - test1,test2
extension - .csv
Id - 1 and file name - test1
completepath - C:\Users\Documents\ReusableQueries\test1.csv
Result of api command1 call for Id : 1 and fileName: test1
Id - 2 and file name - test2
completepath - C:\Users\Documents\ReusableQueries\test2.csv
Result of api command1 call for Id : 2 and fileName: test2
for) loops. Given thatIdis always numeric and consecutive, remove thefor %%iloop, doset /A "Id=0"before thefor %%floop, doset /A "Id+=1"as first command in the loop body and use!Id!instead of%%i...