I need to pick a random filename from specific directory N times but how to get it when both array and index variable must be called using delayed expansion?
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A filesCount=0
FOR %%f IN (*) DO (
SET files[!filesCount!]=%%~f
SET /A filesCount+=1
)
FOR /L %%x IN (1, 1, !N!) DO (
SET /A srcIndex=!random! %% !filesCount!
SET srcFile=!files[!srcIndex!]!
ECHO srcFile
)
ENDLOCAL
The problem at SET srcFile=!files[!srcIndex!]!
.
Now it looks like "value of files[
then srcIndex
and then value of ]
"
How to make it "value of files[i]
where i
is value of srcIndex
"?