Browse - Programming Tips - How can I check if a file exists in a batch file?

Date: 2018aug31
OS: Windows
Language: batch
Keywords: .bat, script

Q.  How can I check if a file exists in a batch file?

A.

if exist c:\path\to\your\file.txt ( rem file exists ) else ( rem file does not exist )
For example, delete a file if it exists
if exist c:\temp\mytemp.tmp ( del c:\temp\mytemp.tmp )