Welcome, guest | Sign In | My Account | Store | Cart

Command language supports creation array. For example:

Batch, 21 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
@echo off
  setlocal enabledelayedexpansion
    ::incremental varibale
    set "i=0"
    ::store filenames into array
    for /f "tokens=*" %%f in ('dir /b') do (
      set arr[!i!]=%%f & set /a "i+=1"
    )
    ::display all array items
    set arr
    ::just line
    echo.===================================
    ::print array items (from 0 till n)
    set "len=!i!"
    set "i=0"
    :loop
    echo !arr[%i%]! & set /a "i+=1"
    if %i% neq %len% goto:loop
  endlocal
  ::another way to create array arr.!i!=%%f
exit /b
Created by greg zakharov on Thu, 1 Nov 2012 (MIT)
Batch recipes (42)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks