SOLVED: Error: #Include file "myfile.ahk" cannot be opened
SOLVED: Error: #Include file "myfile.ahk" cannot be opened
Hi every1,
I'm sure I'm missing something microscopic but important (as is the case with most programming errors lol) but when trying to include a file I get this:
Error at line 13 [or wherever I try to put the #Include statement]
#Include file "myfile.ahk" [with or without quotes] cannot be opened [why? lol]
The program will exit. [Gee thanks]
The script I'm trying to include is in the same folder and is spelled correctly in the script I'm trying to include it in. I right-clicked it and went to Properties, and it's not marked as Read-Only. So for some mysterious reason, it just "cannot be read"... Any idea what's going on? Thanks.
I'm sure I'm missing something microscopic but important (as is the case with most programming errors lol) but when trying to include a file I get this:
Error at line 13 [or wherever I try to put the #Include statement]
#Include file "myfile.ahk" [with or without quotes] cannot be opened [why? lol]
The program will exit. [Gee thanks]
The script I'm trying to include is in the same folder and is spelled correctly in the script I'm trying to include it in. I right-clicked it and went to Properties, and it's not marked as Read-Only. So for some mysterious reason, it just "cannot be read"... Any idea what's going on? Thanks.
Last edited by Miguel7 on 27 Sep 2014, 21:50, edited 1 time in total.
Re: Error: #Include file "myfile.ahk" cannot be opened
The path of a file or directory as explained below. This must not contain double quotes, wildcards, or variable references except %A_ScriptDir%, %A_AppData%, %A_AppDataCommon% and (in v1.1.11+) %A_LineFile%. Escape sequences other than semicolon (`;) must not be used, nor are they needed because characters such as percent signs are treated literally.
File: The name of the file to be included, which is assumed to be in the startup/working directory if an absolute path is not specified (except for ahk2exe, which assumes the file is in the script's own directory). Note: SetWorkingDir has no effect on #Include because #Include is processed before the script begins executing.
Directory: Specify a directory instead of a file to change the working directory used by all subsequent occurrences of #Include and FileInstall. Note: Changing the working directory in this way does not affect the script's initial working directory when it starts running (A_WorkingDir). To change that, use SetWorkingDir at the top of the script.
Source: #Include
Some other unlikely causes: the user running the script might not have permission to access the file, or some other program might have it locked for reading.A script's initial working directory is determined by how it was launched. For example, if it was run via shortcut -- such as on the Start Menu -- its working directory is determined by the "Start in" field within the shortcut's properties.
Source: SetWorkingDir
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be open
Yeah, I didn't think adding quotes would help, but at that point I was grasping at straws. But the part you put in bold ("...assumed to be in the startup/working directory...") seems to be what caused the problem. That's still a bit of a surprise, since I've never had to do this before, but whatever - bottom line is, I got it working by sticking "%A_ScriptDir%/" (without the quotes) before the file name. Thanks again.
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be open
Did you change the way that you were launching the script?
I wrote:A script's initial working directory is determined by how it was launched.
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be open
I'm not really sure what you mean, "how" it was launched... do you mean whether or not I did a right-click and chose "Run Script" vs. double-click on the file? I think I'm going to need to research the page you are referring to (about the "working" directory - which up till now has meant the same thing as %A_ScriptDir%).
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be open
By "how", he means directly opening it vs. opening it with a shortcut/script/etc.. By default, the working directory is the script directory. There can be an exception in that when opening it with another script or shortcut. The working directory can be changed at (almost) any time with SetWorkingDir, so they are not the same.
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be open
It only appears that way because you usually launch scripts using Explorer. In v1, the initial working directory is exactly whatever the parent process set it to when launching AutoHotkey.exe. When launching by double-clicking in Explorer, that's usually the directory containing the file being launched. (The difference is that the working directory is set by Explorer, which knows nothing about scripts or script directories.)By default, the working directory is the script directory.
In v2, #include is relative to the directory which contains the current file (A_LineFile), and the working directory defaults to A_ScriptDir.
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be opened
Can anyone translate this in german?
I also have this problem...
I also have this problem...
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be opened
Hallo David, ich probiers mal:David wrote:Can anyone translate this in german?
I also have this problem...
Hier wurde keine explizite Pfadangabe für das include-File verwendet. In so einem Fall sucht AHK im aktuellen Arbeitsverzeichnis des Skripts nach dem include-File.
Das Problem lag hier jedoch darin begründet, dass das Arbeitsverzeichnis des Skripts ein anderes war als vom Fragesteller erwartet. Dieses 'working directory' ist nämlich davon abhängig, wie das Skript gestartet wird (z. B. Doppelklick im Explorer oder Verknüpfung im Start-Menü).
Hier wurde das Problem gelöst, indem eine Pfadangabe hinzugefügt wurde - in diesem Fall ergab das: #Include %A_ScriptDir%\myfile.ahk, weil hier der include-File im gleichen Verzeichnis lag wie das Hauptskript; andere (auch absolute) Pfadangaben sind natürlich auch möglich (z. B. #Include C:\My Documents\Scripts\myfile.ahk )
Oder man setzt alternativ vorher das Arbeitsverzeichnis explizit mit SetWorkingDir oder z. B.:
#Include %A_ScriptDir% ; Setzt das Arbeitsverzeichnis für folgende #Includes
Wir haben hier übrigens auch ein deutschsprachiges Forum http://ahkscript.org/boards/viewforum.php?f=8 . Am besten fügst du immer den Programmcode zu deinem Post hinzu, der bei dir nicht funktioniert (idealerweise noch weitere Infos wie Windows-Version und AHK-Version) und beschreibst dein Problem so genau wie möglich.
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be opened
be careful the error mesage isn't accurate:
I got the error:
Try to comment stuff on your script to check if it comes from there.
I got the error:
but the path was ok, it's only the script I included which contained an error.Error: This parameter contains a variable name missing its ending percent sign.
Try to comment stuff on your script to check if it comes from there.
Re: SOLVED: Error: #Include file "myfile.ahk" cannot be opened
That's clearly a different error message than discussed in this old topic.