1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple .bat question - dump contents of 2 dimensional array

Discussion in 'Support' started by ccb, Jan 3, 2012.

  1. ccb

    ccb

    Joined:
    Jul 13, 2009
    Messages:
    44
    Likes Received:
    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])
    
    Thanks for any help...
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,280
    Likes Received:
    38
    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...?
     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    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...
     

Share This Page