Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Simple .bat question - dump contents of 2 dimensional array

  • Thread starter Thread starter ccb
  • Start date Start date
Jul
47
0
>ver
TCC 13.03.37 x64 Windows 7 [Version 6.1.7601]

I haven't worked with a .bat/.cmd/.btm file in a long time...
I use the sift plugin to create an array:
Code:
>sift 10 largest biguns
10 largest files sifted into BIGUNS[10,3].
From the command line, this works as expected:
Code:
>do i = 0 to 3 (echo %BIGUNS[%i,0])
tmp1F8E.tmp
fla7C.tmp
~DF0A9116212CDE5BE1.TMP
tmpEF1A.tmp
However, when I try to do the same thing in a batch file (where __rowCnt and __arrName are parameters to the batch file):
Code:
set __arrName=%1
set __rowCnt=%2
do i = 0 to %__rowCnt (echo %__arrName[%i,0])
>c:\bin\dumpArray.bat BIGUNS 3
BIGUNS[0,0]
BIGUNS[1,0]
BIGUNS[2,0]
BIGUNS[3,0]

Thanks for any help...
 
I don't see any straightforward way to do a delayed expansion of an array variable. Here's a nasty Rube Goldberg approach:

Code:
do i = 0 to %__rowCnt ( echo %@execstr[echo %%%__arrName[%i,0]] )

If you're also using my SafeChars plugin, you could also:

Code:
do i = 0 to %__rowCnt ( echo %@safeexp[%__arrName[%i,0]] )

Perhaps someone else can come up with something a little more elegant...?
 
AFAIK array names cannot be specified indirectly. Your two methods are as simple as possible. I had written an ARRAY2FILE batch program, and used the @EXECSTR approach. @SAFEEXP would have been safer, though...
 
Back
Top
[FOX] Ultimate Translator
Translate