if else [solved]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
masterfrog
Posts: 2
Joined: 23 Feb 2023 07:07

if else [solved]

#1 Post by masterfrog » 23 Feb 2023 07:32

Hello together,

i have a problem with a simple task.
This is my one-line-code which is directly run in cmd.exe (not in an Batch-File):

Code: Select all

C:\Temp>if not exist test.txt ( echo "not there" ) else ( echo "it's there" ) & echo "let's do the next things"
My Problem is, that the code echos only "not there" if the test.txt doesn't exist. But it doesn't echo the "let's do the next things".
The Task should check if the file exists or not and no matter what the result is, it should continue wich the statement after the last &.
Unfortunately it interprets the "& echo "let's do the next things" as a part of the else statement.

I can't solve it in a batch file because of restrictions, so i need to do it directly on the prompt line.

It would be great, if someone can help me.
I am using windows 10.

Kind regards
Stefan
Last edited by masterfrog on 24 Feb 2023 03:13, edited 1 time in total.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: if else

#2 Post by Aacini » 23 Feb 2023 09:01

Use this way:

Code: Select all

C:\Temp> ( if not exist test.txt ( echo "not there" ) else echo "it's there" ) & echo "let's do the next things"
Antonio

masterfrog
Posts: 2
Joined: 23 Feb 2023 07:07

Re: if else

#3 Post by masterfrog » 24 Feb 2023 03:12

Helllo Antonio,

thank you very much for your fast answer.
It works! :D

Kind regards
Stefan

Post Reply