T3RRYT3RR0R

Batch Assign Array Values in For Loop

Dec 28th, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.59 KB | None | 0 0
  1. @ECHO OFF
  2.  
  3. ::: Delayed Expansion required to access variables during operation of For Loop
  4. ::: Random only used for demonstration purpose. Normal use would be to define array values in a text file to be
  5. ::: "Loaded into" the Arrays.
  6.  
  7. ::: For /L defines the number of arrays to be set.
  8. ::: For /F is where you would adjust the input for the arrays.
  9.  
  10. SETLOCAL ENABLEDELAYEDEXPANSION
  11. FOR /L %%i IN (1,1,5) DO FOR /F %%j IN ('SET /A "RND=!RANDOM!*15/32768+1"') DO ECHO ARRAY[%%i] %%j && Set "aVal=%%i" && Set "Array[!aVal!]=%%j"
  12.  
  13.  
  14. ECHO %Array[1]% %Array[2]% %Array[3]% %Array[4]% %Array[5]%
  15.  
  16. pause
Advertisement
Add Comment
Please, Sign In to add comment