## Filenames - quotation marks or no quotation marks?

Get help with using AutoHotkey and its commands and hotkeys
yogalD
Posts: 3
Joined: 25 Apr 2016, 06:36

### Filenames - quotation marks or no quotation marks?

A very annoying syntax issue I'm having with AHK right now:
I can't find any way to determine if a file is empty, so I wrote a function to do so.

Code: Select all

``````CheckEmpty(file) {
if (temp="") {
return 1
} else {
return 0
}
}
msgbox  % "File empty status: " . CheckEmpty("D:\common\preferences\prefs.cs")
``````
The only problem is, calling the CheckEmpty function requires me to have quotation marks. However, the function does not let me use quotation marks in the file name (otherwise FileReadLine returns nothing). If I don't have quotation marks in the CheckEmpty function call it says, "The leftmost character above is illegal in an expression."
Last edited by yogalD on 25 Apr 2016, 09:07, edited 1 time in total.
HotKeyIt
Posts: 2130
Joined: 29 Sep 2013, 18:35
Contact:

### Re: Filenames - quotation marks or no quotation marks?

Btw. I would rather use FileGetSize, size, %file%.

Code: Select all

``````CheckEmpty(file) {
FileGetSize, size, %file%
return !!size
}
msgbox  % "File empty status: " . CheckEmpty("D:\common\preferences\prefs.cs")``````
yogalD
Posts: 3
Joined: 25 Apr 2016, 06:36

### Re: Filenames - quotation marks or no quotation marks?

Thanks, it still doesn't make any logical sense to me, but hey it works.

Also I did realise of course that the first line being empty doesn't mean the whole file is empty but it was what I needed at the time.
boiler
Posts: 5295
Joined: 21 Dec 2014, 02:44

### Re: Filenames - quotation marks or no quotation marks?

When you're passing a literal string (rather than a variable that contains the string) as an argument in a function call, you use expression syntax, which requires it to be in quotes. If you were to use the literal string in a command like FileReadLine, then it requires you to use "traditional" syntax rather than expression syntax, unless you force it to use expression syntax with a % followed by a space. I know it makes things confusing while learning the language.

Example using a literal string with traditional syntax:

Example using a literal string with forced expression syntax:

Similarly, you can use traditional or expression syntax if you use a variable instead of a literal string as HotKeyIt showed. So the above examples using a variable become:

Forced expression:
FileReadLine,temp, % file, 1 (subtle but important difference)

In fact, the assignment of the variable itself can be done either way, affecting both the assignment operator and the way the value is shown.

file = D:\common\preferences\prefs.cs

Expression:
file := " D:\common\preferences\prefs.cs"
yogalD
Posts: 3
Joined: 25 Apr 2016, 06:36

### Re: Filenames - quotation marks or no quotation marks?

Perhaps everything should be forced to expression syntax, it's too inconsistent having two different types. Oh well.