sorry in advance if theres a thread on here to answer my question, I've been stuck on this since friday and was searching around. I did find some similar-ish problems but none I could apply or adapt to this (to my knowledge).
In short, I have a batch script, that creates a text file of a directory, the script then searches for a file within the directory. If the files theres it closes out, if the file isnt there it runs an installer.
My script atm is looking like this:
@echo off
dir "C:\SomeDirectory" > DIRECTORY.txt
timeout 5 >Nul
findstr "SomeProgram.exe" DIRECTORY.txt
if ErrorLevel = 0 (
@echo Program Found! > SCN.txt
)
else (
@echo Program Not Found! >SCN.txt
start ahkbin.exe
)
Im getting two issues when i'm running this.
(1) The else condition always prints to the .txt file specified, even when the directory exists, and the string in the directory.txt is there. If I switch the conditions around the same occurs in vice versa.
(2) No matter where "start ahkbin.exe" is placed, it executes. if placed in both IF and ELSE it executes twice.
I feel like I'm doing something clearly incorrect in how i've structured the IF\ELSE loop or how i'm using information from the text files, or else i'm just incorrectly using a batch file.
Any input would be greatly appreciated, Thanks in advance, LMacs.