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

nested for loop question

Discussion in 'Support' started by rawood11, Dec 22, 2008.

  1. rawood11

    Joined:
    Oct 2, 2008
    Messages:
    19
    Likes Received:
    0
    These nested for loops

    FOR %x IN (@statsdates) (
    Echo date= %x
    for %y in (m:\taqDAILYTRF\%x) (
    echo tickers= %y
    )
    )

    produces this result:

    date= 20070601
    tickers= m:\taqDAILYTRF\20070601

    The first loop works fine -- the second loops fails to list the members of m:\taqDAILYTRF\%x

    What am I missing?
     
  2. dim

    dim Dimitry Andric

    Joined:
    May 31, 2008
    Messages:
    203
    Likes Received:
    0
    On 2008-12-22 20:24, rawood11 wrote:

    It's hard to answer your question without knowing:
    * The contents of the "statsdates" file
    * The directory listing of m:\taqDAILYTRF

    My first guess would be that the directory you want to see simply
    doesn't exist, or you don't have permission to view it.
     
  3. rawood11

    Joined:
    Oct 2, 2008
    Messages:
    19
    Likes Received:
    0
    figured out the problem -- /D needed to be removed (show directories only)

     
  4. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Seems to me you are missing the @ sign in front of the second filename.

    If the desire is to display the contents of the second file (i.e.
    m:\taqDAILYTRF\%x) you need to preface it with the @ sign like you did for
    your outer loop. If %x references a directory as opposed to a file, you
    could use "m:\taqDAILYTRF\%x\*" to get a listing of all the files in that
    directory.

    FOR %x IN (@statsdates) (
    Echo date= %x
    for %y in (@m:\taqDAILYTRF\%x) (
    echo tickers= %y
    )
    )

    The above loops are almost always better off done with a DO loop due to
    the fact that the above multi-line statement is in fact a single
    statement. Since you have it written as a multiline statement, I assume
    it is part of a batch file. Debugging becmes *much* easier when using
    DO/ENDDO.

    DO x IN @statsdates
    Echo date= %x
    DO y in @m:\taqDAILYTRF\%x
    echo tickers= %y
    ENDDO
    ENDDO

    -Scott

    "JP Software Forums" <neil@jpsoft.com> wrote on 12/22/2008 02:24:17 PM:


     

Share This Page