I.e.: get first path that exists, if none exist, return.
I was curious for the best code to do this. Method 1 below has an awkward Sleep 0, method 2 works but is not ideal. Cheers.
Code: Select all
q::
vPath1 := "C:\MyDir1\notepad.exe"
vPath2 := "C:\Windows\System32\notepad.exe"
vPath3 := "C:\MyDir2\notepad.exe"
vPath4 := "C:\Windows\SysWOW64\notepad.exe"
;method 1
if FileExist(vPath := vPath1)
|| FileExist(vPath := vPath2)
|| FileExist(vPath := vPath3)
|| FileExist(vPath := vPath4)
Sleep 0
else
return
if FileExist(vPath)
MsgBox, % "1 " vPath
;method 2
Loop, 4
if FileExist(vPath%A_Index%)
{
vPath := vPath%A_Index%
break
}
if !FileExist(vPath)
return
if FileExist(vPath)
MsgBox, % "2 " vPath
return
Code: Select all
EditScript(vPath, vPathExe="")
{
if FileExist(vPathExe)
|| FileExist(vPathExe := "C:\Windows\System32\notepad.exe")
|| FileExist(vPathExe := "C:\Program Files\Windows NT\Accessories\wordpad.exe")
Sleep 0
else
return
Run, "%vPathExe%" "%vPath%"
}
Code: Select all
q::
vPath1 := "C:\MyDir1\notepad.exe"
vPath2 := "C:\Windows\System32\notepad.exe"
vPath3 := "C:\MyDir2\notepad.exe"
vPath4 := "C:\Windows\SysWOW64\notepad.exe"
;method 1
if !FileExist(vPath := vPath1)
&& !FileExist(vPath := vPath2)
&& !FileExist(vPath := vPath3)
&& !FileExist(vPath := vPath4)
return
MsgBox, % vPath
return
Functions
https://autohotkey.com/docs/Functions.htm#ShortCircuit