3

Pseudo code:

if file exists: do xxxx done else: do xxxx done 
1

2 Answers 2

6

You can use exist:

if exist somefile.dat echo It exists 

Depending on the "dialect", you can use else statements. At the lowest level, though, some rather ugly logic like this works:

if exist somefile.dat goto fileexists echo file does not exist goto alldone :fileexists echo file exists :alldone 
Sign up to request clarification or add additional context in comments.

Comments

4

Syntax is as follows:

IF [NOT] EXIST filename command

You can use the [NOT] option to execute code if a file doesn't exist as opposed to if the file does exist, however this can be done as an ELSE staement in a standard IF EXIST statement.

IF EXIST stuff.txt ( ECHO It exists ) ELSE ( ECHO It doesn't exist ) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.