Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an array in batch in multiple lines

I am trying to copy a list of files to a specific directory using a batch file. The first thing I need to do is to create a list of file names. I saw this this post Create list or arrays in Windows Batch. The following works fine. But I am not happy about the fact that it is in one line. As my list of files gets bigger and bigger, it becomes hard to read.

set FILE_LIST=( "file1.txt" "file2.txt" "file3.txt" )

And then I noticed this blog. It creates an array with multiple lines.

set FILE_LIST[0]="file1.txt"
set FILE_LIST[1]="file2.txt"
set FILE_LIST[2]="file3.txt"

I am wondering whether there is a way of creating a array as the following:

set FILE_LIST=( "file1.txt" 
     "file2.txt" 
     "file3.txt" )

so that I can separate the file names into multiple lines, while do not need to worry about the index.

like image 280
Yuchen Avatar asked May 22 '14 14:05

Yuchen


2 Answers

In the same topic you refer to there is the equivalent of this solution (below "You may also create an array this way"):

setlocal EnableDelayedExpansion
set n=0
for %%a in ("file1.txt"
            "file2.txt"
            "file3.txt"
           ) do (
   set FILE_LIST[!n!]=%%a
   set /A n+=1
)
like image 64
Aacini Avatar answered Sep 20 '22 01:09

Aacini


Exactly repeat indents

set arr=(^
    "first name"^
    "second name"^
)

Check data

for %%a in %arr% do (
    echo %%a
)
like image 41
Redee Avatar answered Sep 22 '22 01:09

Redee