11 Vote

Abort Batch Script if File does not exist

Question by Guest | Last update on 2021-04-06 | Created on 2016-11-05

Before my Windows Batch Script (.BAT) really takes up ride, I want to check whether all necessary files for the commands are present at all.

Therefore, I want to achieve that the script just discontinues and terminates itself if the requirements and required files are not existing. With this, I want to prevent the script to stop half finished somewhere in the middle.

Is there any possibility to do that? Can someone help me?

ReplyPositiveNegative
0Best Answer2 Votes

Whether a file is existing can easily be checked with "IF EXIST <FileName>". If you want to check whether a file is not existing, you can just use "IF NOT EXIST" instead. The command "EXIT" cancels the script execution.

So, in your case you can just add the following line for each required file:

IF NOT EXIST important-file.dat EXIT

If the file "important-file.dat" is not existing, the command after the check will be executed and the whole script terminates. If the file is existing, the next line will be processed.
Last update on 2021-04-06 | Created on 2016-11-06

ReplyPositive Negative
Reply

Related Topics

PHP: File Download Script

Tutorial | 0 Comments

Rename File to its Folder Name

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.