As the title says, I'm trying to pick up to four random files (wallpapers) from a folder, for further processing. The folder does not contain subfolders, just *.jpg's, *.bmp's and *.png's (it may contain a Thumbs.db file, but I already took care of that).
I read all the files with a for
loop making something similar to an array, then I'd like to run another for
loop for making the random numbers that will act as indexes for choosing the files.
setlocal enabledelayedexpansion
set "wps=1 2 3 4"
set /a ind = 0
for /f "tokens=* delims=" %%g in ('dir C:\Wallpapers /a:-h-s /b /s') do (
set /a ind += 1
set "!ind!=%%g"
)
for %%g in (%wps%) do (
set /a "num = (((!random! & 1) * 1073741824) + (!random! * 32768) + !random!) %% %ind% + 1"
echo Wallpaper %%g is #!num! - Title: "!!num!!"
)
Of course the line that echoes just outputs Wallpaper 1 is #118 - Title: "118"
instead of Wallpaper 1 is #118 - Title: "C:\Wallpapers\Miami Skyline.jpg"
.
So my specific question is: how can I double expand a variable inside a for
loop?
[Note #1: the line that creates the random number needs to be so long because it gives a good random distribution of values]
[Note #2: I need wps
to be stored that way, because sometimes I could need just three wallpapers, not necessarily in numerical order]