user393148
user393148

Reputation: 957

Return items in random order from a loop

Is there a windows command line to return items from a list in random order?

         FOR %%g in (dir1 dir2 dir3 dir4) DO (
         //do something with any dir returned in random order
         )

Thanks

Upvotes: 0

Views: 100

Answers (1)

dogbane
dogbane

Reputation: 274632

Here is some sample code which may help you. It generates a random number between 0 and 2 (inclusive) and then uses that to pick a directory to work on:

@echo off
setlocal enabledelayedexpansion

set /A R=%random%%% 3

set /A Counter=0
FOR %%g in (dir1 dir2 dir3 dir4) DO (
    if !Counter!==%R% echo %%g
    set /A Counter+=1
)

Upvotes: 1

Related Questions