problem with "if FileExist"

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
raf58
Posts: 2
Joined: 09 Mar 2020, 06:24

problem with "if FileExist"

19 Apr 2021, 12:51

hello everybody

I have a small but very ennoying issue, just starting to play with AutoHotkey
already spent severals hours to find out why

in the tiny test code below, the 1st msgbox says "YES" but the 2nd (with %var%) says "NOT"

why??
what is the solution to pass as parameter the filename ?

thanks for any input !

Code: Select all

#y::
var=mydoc.txt
if FileExist("c:\mydoc.txt")
MsgBox, YES_exists 
else MsgBox, ...NOT_exists

if FileExist("c:\%var%")
MsgBox, YES_exists 
else MsgBox, ...NOT_exists

return
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: problem with "if FileExist"

19 Apr 2021, 13:19

In expression mode (which includes the parameter section of a function call), literal strings need to be quoted, and variables should have no %s around them. You can concatenate these different parts:

Code: Select all

if FileExist("c:\" var)
raf58
Posts: 2
Joined: 09 Mar 2020, 06:24

Re: problem with "if FileExist"

19 Apr 2021, 14:51

ah!
thank you, works fine

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 337 guests