.bat If Then Statement

jmituzas picture jmituzas · Aug 31, 2010 · Viewed 39.7k times · Source

I need help with writing a batch script for

if file newfile.txt exists
then  del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"

Answer

Rudu picture Rudu · Aug 31, 2010

You can use simple curved brackets (also supporting else!)

@echo off
IF EXIST newfile.txt (
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
)

With else:

@echo off
IF EXIST newfile.txt (
del "InDesignData.txt"
ren "newfile.txt" "InDesignData.txt"
) else (
echo Making tea
)