FileExist is not working with variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dinu99
Posts: 1
Joined: 24 Mar 2020, 22:24

FileExist is not working with variables

Post by dinu99 » 01 Dec 2022, 07:02

I have following code with FileExist function with paramaters but it is not working. Please help find the issue.

Code: Select all

filename := "textfile"
if (FileExist("C:\Users\%A_UserName%\Documents\subFolder\%filename%.text"))
{
  Run ""C:\Users\%A_UserName%\Documents\subFolder\%filename%.one""
} 
else 
{
  MsgBox, File %filename% is missing.
}

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: FileExist is not working with variables

Post by mikeyww » 01 Dec 2022, 07:57

Welcome to this AutoHotkey forum!

AutoHotkey function parameters are expressions.
Variable names in an expression are not enclosed in percent signs (except for pseudo-arrays and other double references).

Code: Select all

MsgBox, % FileExist(A_MyDocuments "\subFolder\" filename ".text")

Post Reply

Return to “Ask for Help (v1)”