Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Batch File Nested IF

Posted on 2010-09-16
5
Medium Priority
?
1,373 Views
Last Modified: 2012-05-10
I am trying to add the last bolded ELSE . . . to this batch code without success.

I have tested both ELSE as good but can not add them together.

How do I get FOR /F to see multiple nested IF Statements?

FOR /F "Tokens=1-3,* Delims=^*" %%A IN ('Type "%SourceFile%"') DO IF "%%A%%B"=="NM1IL" (ECHO %%D >> "%OutputFile%") ELSE (IF "%%A%%B"=="NM185" ECHO %%D >> "%OutputFile%") ELSE (IF "%%A%%B"=="REFD9" ECHO %%C >> "%OutputFile%")
0
Comment
Question by:tonydemarco
  • 3
  • 2
5 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 33693991
FOR /F "Tokens=1-3,* Delims=^*" %%A IN ('Type "%SourceFile%"') DO (
  IF "%%A%%B"=="NM1IL" (
    ECHO %%D >> "%OutputFile%"
  ) ELSE (
    IF "%%A%%B"=="NM185" (
      ECHO %%D >> "%OutputFile%"
    ) ELSE (
      IF "%%A%%B"=="REFD9" ECHO %%C >> "%OutputFile%"
    )
  )
)
0
 
LVL 9

Author Closing Comment

by:tonydemarco
ID: 33694094
Excellent!
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 33694322
Thanks, glad that helped.

~p
0
 
LVL 9

Author Comment

by:tonydemarco
ID: 33695224
Wanting to Add:
IF "%%A"=="N3" (ECHO %%B >> "%OutputFile%"
to your solution below and should I be looking at an easier way to add to the search criteria?

Putting this in a new Question to follow . . .

FOR /F "Tokens=1-3,* Delims=^*" %%A IN ('Type "%SourceFile%"') DO (
  IF "%%A%%B"=="NM1IL" (
    ECHO %%D >> "%OutputFile%"
  ) ELSE (
    IF "%%A%%B"=="NM185" (
      ECHO %%D >> "%OutputFile%"
    ) ELSE (
      IF "%%A%%B"=="REFD9" ECHO %%C >> "%OutputFile%"
    )
  )
)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question