IF EXIST, CONTINUE

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
falcios
Posts: 41
Joined: 02 Mar 2017 05:38

IF EXIST, CONTINUE

#1 Post by falcios » 02 Jul 2021 16:11

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.

rasil
Posts: 31
Joined: 23 Apr 2020 13:05

Re: IF EXIST, CONTINUE

#2 Post by rasil » 02 Jul 2021 17:23

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

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

Re: IF EXIST, CONTINUE

#3 Post by aGerman » 03 Jul 2021 03:56

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

Post Reply