0

I currently need a batch script (Windows) that allows me to attempt to delete a file, and if it fails, perform another action:

e.g.: del C:\test.bin
if fail attempt kill C:\test.bin
else echo Success

kill C:\test.bin
if success attempt del C:\test.bin
else echo Unable to kill process

2 Answers 2

2
del "C:\test.bin" >nul 2>&1
if exist "C:\test.bin" (
    echo failed
) else (
    echo success
)
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of batch files, I suggest looking at the much more powerful Power Shell.

1 Comment

For such a trivial task? A bit overkill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.