Page 1 of 1

Having an issue with echoing data from nested for loops

Posted: 10 Jun 2013 16:02
by Acy Forsythe
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

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

Posted: 10 Jun 2013 16:34
by aGerman
What about
... DO (SET "DLR=%%k")
and
... DO (SET "ACCT=%%n")

Seems you mislocated the quotation marks.

Regards
aGerman

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

Posted: 11 Jun 2013 07:08
by Acy Forsythe
Thanks aGerman. I knew it was something simple I was missing. Can't believe I didn't spot that.