Reputation: 386
d:
IF EXIST D:\JDK Folder\bin\awt.dll (echo youhavejava) ELSE (echo youdonthavejava)
pause
I wanted to make this program to check if a file exists on my computer or not and it will tell me the answer. I have tried to get this code to work, but no matter what I do it won't work. Can someone please tell me what the problem is? All it does is run and not output anything.
Upvotes: 2
Views: 29906
Reputation: 1607
You need quotes around the file path, because there is a space in it.
IF EXIST "D:\JDK Folder\bin\awt.dll" (echo youhavejava) ELSE (echo youdonthavejava)
Upvotes: 8
Reputation: 23
Unless you want a custom message, an easy way of achieving this is to use dir. This message will also be useful for checking if certain folders exist, and not just files.
Example:
dir C:\Users\Username\Desktop\RandomFile.exe
If the path specified is valid, it will return with
Volume in drive C has no label.
Volume Serial Number is xxx
Directory of C:\Users\Username\Desktop
And then it will specify stuff like the file name, dates, etc.
If the file or path does not exist, it will return with
File Not Found
Upvotes: -1