dimanche 30 juillet 2017

quick-pick a random file from a tree of 15 thousand files

I found this code for picking a random file but it is way too slow, taking a minute or few to run through every file (15000+ files):

setlocal EnableDelayedExpansion
cd /d "%~1"
set n=0
for /r %%f in (*.*) do (
   set /A n+=1
   set "file[!n!]=%%f"
)
set /A "rand=(n*%random%)/32768+1"

echo "!file[%rand%]!"

I need a way faster solution here.




Aucun commentaire:

Enregistrer un commentaire