开发者

Return items in random order from a loop

开发者 https://www.devze.com 2023-02-05 00:48 出处:网络
Is there a windows comm开发者_开发知识库and line to return items from a list in random order?

Is there a windows comm开发者_开发知识库and 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


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
)
0

精彩评论

暂无评论...
验证码 换一张
取 消