Batch Script: Check if File exists
Question by Guest | Last update on 2021-04-06 | Created on 2016-08-29
I would like to check whether a specific file exists using a Windows Batch Script (.BAT) before going on with the script.
Is there any possibility to do so? I have never worked with conditions in batch scripts before.
Related Topics
Windows Batch Script: Computer Shutdown
Tutorial | 2 Comments
PHP: File Download Script
Tutorial | 0 Comments
How to resize Image before Upload in Browser
Tutorial | 13 Comments
Lazarus: Load File as Byte Array and save Byte Array as File
Tutorial | 0 Comments
SQLite: Check whether Table exists
Info | 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.
For checking whether a file exists, you can just write "IF EXIST".
Behind that, you can write the file name and the action that should be executed in the case that the file exists. Here is an example:
With this line, first, it is checked, whether the file c:\test.txt exists. If yes, the file will be opened in the program notepad.
If you want to check for nonexistence, you can use IF NOT EXIST:
This writes the text "file does not exist" into the console if the file c:\test.txt is not existing.
If you cannot or do not want to write all commands into one line, you can also use the following syntax:
Additionally, I have worked with a variable in this example. "F" is first set to our file and afterwards, it is invoked with %F%.
2016-08-29 at 18:28