OR + FileExist good syntax Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
oilali
Posts: 4
Joined: 19 Sep 2017, 08:12

OR + FileExist good syntax

25 Sep 2017, 09:02

Hi, I need quick help.

I'm trying to check two files with "FileExist" function.

Code: Select all


if FileExsist %filename1% OR FileExist %filename2% 
{
do something.
} 
else 
{
do something else.
}

... but I can't use this syntax. (or some similar syntaxes)

What is the right usage of OR statement in AHK in this case? Thank you!

( update: maybe I can't reach my %filename% varible from a previous Label? )

A.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: OR + FileExist good syntax

25 Sep 2017, 09:06

Code: Select all

if FileExist(filename1) OR FileExist(filename2)

;alternatively, and I generally prefer this:
if FileExist(filename1) || FileExist(filename2)
To check your variable do:

Code: Select all

MsgBox, % filename
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
oilali
Posts: 4
Joined: 19 Sep 2017, 08:12

Re: OR + FileExist good syntax

25 Sep 2017, 09:51

Ok, But the script is terminated with an error: "The following variable names contains an illegal character"

Previously, I'm working with this variables without any problems...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: OR + FileExist good syntax

25 Sep 2017, 10:05

It's related to this:

Code: Select all

q:: ;the two meanings of %var%
b := "c"

a := "b"
MsgBox, %a% ;b (get value of a: b)
a := "\"
MsgBox, %a% ;\ (get value of a: \)

a := "b"
MsgBox, % %a% ;c (get value of a: b, get value of b: c)
a := "\"
MsgBox, % %a% ;(causes error) (get value of a: \, get value of \: ERROR)
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: OR + FileExist good syntax  Topic is solved

25 Sep 2017, 10:12

@oilali: Instead of:
if FileExist(filename1) OR FileExist(filename2)
did you do this?:
if FileExist(%filename1%) OR FileExist(%filename2%)
That would give you that error because as jeeswg pointed out, you wouldn't be passing the contents of the variables named "filename1" and "filename2", you would be trying to pass the contents of variables named, say, "Myfile1.txt" and "Myfile2.txt". Not only are those not your variable names, but they have a character (the ".") that is not valid in a variable name.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Fredrik F, garry, maxkill, RandomBoy, ShatterCoder and 417 guests