Having an issue with echoing data from nested for loops

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Acy Forsythe
Posts: 126
Joined: 10 Jun 2011 10:30

Having an issue with echoing data from nested for loops

#1 Post by Acy Forsythe » 10 Jun 2013 16:02

I've got the following batch file, with a bunch of XML files in a directory.

The output I need is:

Date,Dealer,Account

I'm getting date from the directory listing.
Dealer is within the XML file itself with a tag labeled as <Dealer>1234</Dealer>
Account is part of the filename Accountnumber_VerylongUID.xml which I am further parsing from the command line string.

I can get the output I need in the following format:

Date,
Dealer,
Account

Simply by echoing the For Loop Variables as I get them. However... I'd like to get them on the same lines and for that, I believe I need to have them in a single Echo statement. (although I could be wrong).

My delayed expansion doesn't seem to be working right and I'm sure I'm missing something simple, but any help would be appreciated. Here is what I have:

Code: Select all

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET DLR=123
SET ACCT=456

(
    FOR /F "tokens=1,2,3,4,5 delims= " %%A IN ('DIR /OD ^| FIND "xml"') DO (
       
    FOR /F "tokens=3 delims=><" %%k IN ('TYPE %%E ^| FIND "Dealer"' ) DO (SET DLR"=%%k")
    FOR /F "tokens=1 delims=_" %%n IN ("%%E") DO (SET ACCT"=%%n")

    ECHO %%A,!DLR!,!ACCT!

    )
) > Testing.txt

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Having an issue with echoing data from nested for loops

#2 Post by aGerman » 10 Jun 2013 16:34

What about
... DO (SET "DLR=%%k")
and
... DO (SET "ACCT=%%n")

Seems you mislocated the quotation marks.

Regards
aGerman

Acy Forsythe
Posts: 126
Joined: 10 Jun 2011 10:30

Re: Having an issue with echoing data from nested for loops

#3 Post by Acy Forsythe » 11 Jun 2013 07:08

Thanks aGerman. I knew it was something simple I was missing. Can't believe I didn't spot that.

Post Reply