Good day! So I have this task that I have to accomplish in Batch due to heavy system restrictions.
The principle of it, it "randomly" selects files from a folder, and copies them to another folder. The problem is, sometimes the "randomness" selects the same file, thus out of 10 needed files, I end up with 8-9. I have tried to make a "validation" system, but I can't seem to make it work in a loop, so it kinda only does it once, and there is still a chance it will select the same file.
Sorry if the code is a complete spaghetti, im not a programmer
I have a feeling that the solution is really simple, and that i just dont see it Any kind of help, or advice is greatly appreciated Thank you in advance
"Validation" is in "sub3"
@echo off & setlocal enableextensions disabledelayedexpansion
set "workDir=C:\Generator\Tickets"
FOR /L %%n in (1,1,10) DO call :main %%n
goto :sub3
:main
@set /a "rdm=%random%"
set /a "rdm=%random%"
pushd "%workDir%"
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do call :sub1
set /a "rdNum=(%rdm%*%counter%/32767)+1"
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do set "fileName=%%i" &call :sub2
popd "%workDir%"
goto :eof
:sub1
set /a "counter+=1"
goto :eof
:sub2
set /a "counter+=1"
if %counter%==%rdNum% (
xcopy /y "C:\Generator\Tickets\"%fileName%"" "C:\Generator\temp"
)
goto :eof
:sub3
pushd "C:\Generator\temp" && (
for /f "tokens=1,*" %%j in ('
robocopy . . /l /nocopy /is /e /nfl /njh /njs
') do ( if %%j neq 10 goto main)
popd
)
goto :eof