nested for loop question

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Oct 2, 2008
19
0
#1
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?
 

dim

Dimitry Andric
May 31, 2008
203
0
Netherlands
#2
On 2008-12-22 20:24, rawood11 wrote:

> 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
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.
 
Oct 2, 2008
19
0
#3
figured out the problem -- /D needed to be removed (show directories only)

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.
 

samintz

Scott Mintz
May 20, 2008
1,203
11
Solon, OH, USA
#4
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:


> 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?
>
>
>
>