Page 1 of 1

IF EXIST, CONTINUE

Posted: 02 Jul 2021 16:11
by falcios
What commands do I need in my batch file so that if a file exists, then continue?

File: "c:\users\test\sample.txt"

If the file exists, then continue

How would I go about doing this?

Thanks in advance.

Re: IF EXIST, CONTINUE

Posted: 02 Jul 2021 17:23
by rasil
You can do...

Code: Select all

if not exist c:\users\test\sample.txt [command if the file doesn't exist]
This would only do the command if the file doesn't exist. otherwise it will be ignored and your batch file be executed normally

Re: IF EXIST, CONTINUE

Posted: 03 Jul 2021 03:56
by aGerman
rasil is right. Just reverse the logic.

Code: Select all

if not exist "blabla.txt" exit /b
This bails out if the file doesn't exist. In other words, it continues with the next line if the file exists.

Steffen