nested for loop question

Oct 2, 2008
19
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?
 

dim

Dimitry Andric
May 31, 2008
205
1
Netherlands
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
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,503
16
Solon, OH, USA
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?
>
>
>
>
 
Similar threads
Thread starter Title Forum Replies Date
C FOR loop with nested IF / IFF Support 9
B Problem with color in nested shells Support 1
R Problem with %_do_loop in nested do loops Support 2
C Nested IF syntax — TCC behaving differently to CMD Support 12
jbanaszczyk Broken For and nested Do Support 2
vefatica _DO_LOOP and nested DOs? Support 8
vefatica WAD Nested variable expansion in PDIR's @function[*]? Support 13
vefatica Single-line DO inside nested multi-line DOs? Support 9
R How to? debug a nested batch file Support 2
G WAD Nested if exits enclosing if Support 3
M A problem with nested Gosub's/ExecStr's Support 14
C CMD's "nested quote" syntax Support 3
dcantor Terminology question: nested vs. recursive Support 0
J Nested for loops and quotes Support 12
D can PDIR list full filepaths of docs in a nested folder? Support 13
samintz How to? Abort on error DO loop Support 10
D How to use multi-line DO to loop through first level directory names Support 5
vefatica ON ERROR terminates DO loop. Support 0
Dick Johnson for ... do loop "wrap around" Support 11
vefatica Modifying a counted DO loop's counter? Support 1
Z [dos] into - for loop - the bp is not hit Support 5
vefatica Piping the output of a DO loop. Support 4
rps For loop internal %_for_files variable? Support 2
D What is the limit on the compound statement length within ( ) of a FOR-loop? Support 5
old coot Proper use of ON ERRORMSG inside a DO WHILE loop? Support 3
H EndLocal in DO Loop Support 2
B How to? redirect a bunch of loop Support 4
Mike Hall Unexpected "Variable loop" in IF condition Support 10
D Strange issue with FOR loop Support 15
nickles WAD Variable name gets changed within FOR loop Support 2
M tcmd crashes in this recursive "for /f" loop Support 4
G Fixed Slow FOR loop Support 2
S WAD %_do_errors does not report errors when loop control variable type is not directory entry Support 1
mikea 'Loop' on closing TC Support 6
Roedy Loop anomaly Support 6
P Need to use a regex in a "for" loop. Support 54
C forum Posting Question... Support 3
C question re: Move Support 3
S How to? Upgrade Question: What supporting documentation is required at time of purchase? Support 2
Peter Murschall Documentation Question to %@PSHELL Support 4
Fross Tab Question Support 6
Fross Quick Function Question Support 17
Dick Johnson Question about the Touch command Support 0
rps Documentation "Copy+Paste+run" question Support 2
vefatica SFTP question Support 17
vefatica Question about IPWorks Support 0
C How to? SHORTCUT question..... Support 6
vefatica TPIPE, crash and question Support 1
C Question / Suggestion Support 1
MickeyF Another TPIPE question Support 6

Similar threads