Hello AHK Community,
I am having trouble with running programs that may arbitrarily either be located in either of the following locations:
* Location 01 (Run):
C:/Program Files/Foo/Bar/2000.exe
* Location 02 (Run, If the above fails to launch with AHK error Message-box):
C:/Program Files (x68)/Foo/Bar/2000.exe
Notice the difference is the first is from Program-files 64-bit and the other is in Program-files 32-bit directory path. How to run other variant if one doesn't exist? This is because I get an error if the first path doesn't exist so that means it is then assumed it existst on the next variant.
I am thinking this is resolved with an "If statement" or "Else statement". Any ideas?
If Else Statement for Program-files vs x86 variant Topic is solved
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: If Else Statement for Program-files vs x86 variant Topic is solved
Try "Try ...Catch": https://www.autohotkey.com/docs/commands/Try.htm
14.3 & 1.3.7
Re: If Else Statement for Program-files vs x86 variant
This simply solved it (see below). Thank you.
Code: Select all
;;; Shows a message box if a file does not exist.
if !FileExist("C:\Temp\FlagFile.txt")
MsgBox, The target file does not exist.
Re: If Else Statement for Program-files vs x86 variant
I apologize for coming back to this thread. The problem is I don't have the way I was able to make this work using FileExist(). I haven't returned to it until the time came and was left stumped . What ways could I use FileExist() to begin a run command and execute the next run command afterwards in case the first wasn't found?
I should've put the example down when I had it the first time. I let it slip by and now I don't have a reference to it. So, now I need help with getting this resolved once again.
I should've put the example down when I had it the first time. I let it slip by and now I don't have a reference to it. So, now I need help with getting this resolved once again.
Re: If Else Statement for Program-files vs x86 variant
perhaps some context on the nature of the problem?
because the solution is above, you answered your own thread and came back to it, use fileexist to check if the file exists
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||
Re: If Else Statement for Program-files vs x86 variant
This inital reply worked the best. It is one command after another plain and simple just formatted in Braces and not a one-liner type code, so there's workspace using "Try-catch". Unfortunately I am unable to explain what made me say the response afterwards is the clear answer when I simply couldn't figure it out (seriously) (idk, past is the past) .flyingDman wrote: ↑11 Apr 2021, 00:56Try "Try ...Catch": https://www.autohotkey.com/docs/commands/Try.htm
The simple Brace style code to answer (see below on) - How to run an alternative location of the same program (or another in case of an error) in a scenario where the first doesn't exist is using the "Try-catch" syntax when using Autohotkey .
Note: The error message for which the first brace doesn't exist will not display the error and skip to the next brace as you go.
Code: Select all
try
{
Run "C:\Program Files (x86)\foo\bar.exe"
}
catch
{
Run "C:\Program Files\foo\bar.exe"
}
Re: If Else Statement for Program-files vs x86 variant
With a topic title like If Else Statement you had the answer right there.
Examples:
or
Examples:
Code: Select all
if FileExist("C:\Program Files (x86)\foo\bar.exe")
Run "C:\Program Files (x86)\foo\bar.exe"
else
Run "C:\Program Files\foo\bar.exe"
Code: Select all
if FileExist("C:\Program Files (x86)\foo\bar.exe")
Run "C:\Program Files (x86)\foo\bar.exe"
else if FileExist("C:\Program Files\foo\bar.exe")
Run "C:\Program Files\foo\bar.exe"
else
MsgBox, 4112, Error, bar.exe not found!
Re: If Else Statement for Program-files vs x86 variant
Thank you very much Xtra. This code (previous post) seems a whole lot cleaner . I probably did that then, but didn't explain it .