Well, I never knew you could do that! I tried it and it works!
–
Linker3000Sep 21 '10 at 21:24

This cannot possibly work in DOS. DOS doesn't do long file names (only 8.3), and as I recall, DOS doesn't do quotes in file paths either. I don't have a MS-DOS installation handy to see if it supports arrays using a () syntax.
–
Michael KjörlingMay 2 '14 at 9:48

While this does work for your purpose, it should be noted that it is not really an array. It is just a string that is being split into individual elements. You cannot reference the elements directly by doing something like FILE_LIST[0].
–
aphoriaAug 29 '14 at 14:10

From Jakash3's Blog, Arrays in Batch describes how to emulate arrays in the command prompt.

A batch file named array.bat is included in the article, that contains a library of functions used to handle arrays. You will need to select the the text in the article and paste it inside the bat file.

Yes you can do arrays in batch. While they aren't exactly like arrays in C or VB, you CAN do it:

@echo off
setlocal enabledelayedexpansion
set arrayline[0]=############
set arrayline[1]=#..........#
set arrayline[2]=#..........#
set arrayline[3]=#..........#
set arrayline[4]=#..........#
set arrayline[5]=#..........#
set arrayline[6]=#..........#
set arrayline[7]=#..........#
set arrayline[8]=#..........#
set arrayline[9]=#..........#
set arrayline[10]=#..........#
set arrayline[11]=#..........#
set arrayline[12]=############
::read it using a FOR /L statement
for /l %%n in (0,1,12) do (
echo !arrayline[%%n]!
)
pause

+1 you comment that a downvote should be explained. Also, you wrote "you need to use a SINGLE CHARACTER variable as your cursor!" <-- you mean as your index not as your cursor
–
barlopAug 29 '14 at 11:16

Also note that if it's a Win9X boot disk that's DOS (DOS 7). And Windows 9X was still said to run on DOS. And you could add a line to I think it was msdos.sys like bootscan=0 and bootgui=0 that'd stop it booting into Windows and boot straight to a DOS prompt.
–
barlopAug 29 '14 at 13:34

Unfortunately, all of those options are all-inclusive to their respective scopes. I am doing development work, and due to the complex nature of the application every time and want to test a build (which is often) I have to copy five files from the build binary directory to the install binary directory. This gets tedious. Right now, I have the file names hard-coded into my batch script, but I would like to put them into an array to make the script easier to maintain.
–
Jim FellSep 21 '10 at 19:21

For what you want to do, how about using an input variable for each file name, which you can pick up with the %1 %2 etc. variables eg: mybat.bat file1.nam file2.nam etc..

You can then use these variables in a loop but only need to use %1 as the main parameter as you can use SHIFT to bring the other variables into the %1 'position', having a test for null (end of variables) with something like IF "X%1" == "X"

If you save the list of files to filelist.txt, you can get FOR to read and process each line of the file, such as

FOR /F "delims=|" %i IN (filelist.txt) DO @echo %i

to print each line of a file (up to the first "|" in the line. If you don't specify your own delimiter, space and tab will be used, so unless your paths have no spaces, you need to specify a character that will not appear in the file to get complete lines).

I am doing development work, and due
to the complex nature of the
application every time and want to
test a build (which is often) I have
to copy five files from the build
binary directory to the install binary
directory. This gets tedious. Right
now, I have the file names hard-coded
into my batch script, but I would like
to put them into an array to make the
script easier to maintain.

I believe that what you are looking for is a Makefile, and possibly cygwin to give you a decent shell (bash, or whatever your flavour).

Something like this in a batch file? Select a file in a folder.
<< is comment, no code

:selectapk
SETLOCAL ENABLEDELAYEDEXPANSION << DELAYED EXPANSION on for counter in For loop
SET /A MAXITEM=0
Echo.
Echo Found these APK files in "add_apk_here" folder.
Echo.
For %%a in (add_apk_here/*.apk) do (
Set /A MAXITEM+=1
Set MENUITEM!MAXITEM!=%%a << Fill n local env vars, one for each file, called MENUITEM1...n
Echo !MAXITEM!. %%a
)
Echo.
If !MAXITEM!==0 Echo No APK in "add_apk_here" folder & call :delay & Goto start << No apk files then go back
SET /P CHOICE=Select APK to work on:
SET MENUITEM=!MENUITEM%CHOICE%! << Get the stored filename from MENUITEMx
SETLOCAL DISABLEDELAYEDEXPANSION << Very important for next ENDLOCAL that doesn't like the delayedexpansion var
ENDLOCAL & SET apk=%MENUITEM% << put the local MENUITEM var into the global apk var
goto start
:delay
REM %1 like Call :delay 5
SETLOCAL
SET N=%1
If Not Defined N Set N=2
Ping -n %N% -w 1000 127.255.255.255 > nul
ENDLOCAL
Exit /b

You could use names1 names2 names3, rather than names[1] names[2] names[3] by writing names!i! instead of names[!i!]. It produces the array by generating variable names. There isn't an array structure in batch. But it is as neat as any array structure, and populating or printing looks exactly like how one would populate or print an array in a proper language(that actually has the array structure!)

@echo off
setlocal enabledelayedexpansion enableextensions
set i=-1
for %%f in (bob, tom, joseph) do (
set /a i=!i!+1
set names[!i!]=%%f
)
set lastindex=!i!
for /L %%f in (0,1,!lastindex!) do (
echo !names[%%f]!
)

the output-

c:\blah>a
bob
tom
joseph
c:\blah>

Some explanation-

The setlocal enabledelayedexpansion enableextensions with the !var! rather than %var% is necessary to prevent odd behavior, so that variables behave properly when within a FOR or an IF. It's an oddity with batch files. See set /? where that is mentioned further.

This is what populates the array, and is pretty straight forward to anybody that knows about arrays. You could also do names[0]=bobnames[1]=tomnames[2]=joseph though one of the beauties of an array is the ability to populate an array with a loop, which is what i've done here.

for %%f in (bob, tom, joseph) do (
set /a i=!i!+1
set names[!i!]=%%f
)
set lastindex=!i!

This displays the array. %%f if you echo it you'd see will go from 0 to the last index of the array, in steps of 1. so will print names[0] names[1] names[2]