0

What would the contents of a bat file be if I want the following

If a file exists (file name and location)

Then delete the file and then restart the computer

David
  • 275
  • 1
  • 4
  • 17
  • possible duplicate of [How do I Shutdown - Restart - Logoff Windows via bat file](http://stackoverflow.com/questions/162304/how-do-i-shutdown-restart-logoff-windows-via-bat-file). There are literally dozens of questions here about testing to see if a file exists and deleting it. It would appear you've made no effort to research doing this yourself first before posting. (The dupe I linked I found by looking at the **Related** list at the right of this very question without even having to search, and that list was shown to you before you posted the question.) – Ken White Mar 12 '15 at 01:09

1 Answers1

1

It's pretty straightforward -

@echo off
set FileToCheck=NAME_OF_THE_FILE_HERE
if not exist %FileToCheck% goto done
del %FileToCheck%
shutdown /r
:done

You could also use set FileToCheck=%1 instead of hard-coding the filename in your batch file if you want to pass the filename to look for as a command line parameter, i.e. (assuming your batch file is named foo.bat):

c:\>foo RemoveMeAndRebootIfIExist.txt
frasnian
  • 1,893
  • 1
  • 12
  • 24