/docs/commands/_Include.htm
HTML | 55 lines | 47 code | 8 blank | 0 comment | 0 complexity | 79ae65cc03adf4eab0c07ea8b0dfeaa3 MD5 | raw file
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>#Include</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <link href="../static/theme.css" rel="stylesheet" type="text/css" />
- <script src="../static/jquery.js" type="text/javascript"></script>
- <script src="../static/tree.jquery.js" type="text/javascript"></script>
- <script src="../static/content.js" type="text/javascript"></script>
- </head>
- <body>
- <h1>#Include / #IncludeAgain</h1>
- <p>Causes the script to behave as though the specified file's contents are present at this exact position.</p>
- <pre class="Syntax">#Include FileOrDirName
- #Include <LibName>
- #IncludeAgain FileOrDirName</pre>
- <h3>Parameters</h3>
- <dl>
- <dt>FileOrDirName</dt>
- <dd><p>The path of a file or directory as explained below. This <strong>must not</strong> contain double quotes, wildcards, or variable references except <a href="../Variables.htm#ScriptDir">%A_ScriptDir%</a>, <a href="../Variables.htm#AppData">%A_AppData%</a>, <a href="../Variables.htm#AppDataCommon">%A_AppDataCommon%</a> and (in v1.1.11+) <a href="../Variables.htm#LineFile">%A_LineFile%</a>. <a href="_EscapeChar.htm">Escape sequences</a> other than semicolon (<strong>`;</strong>) must not be used, nor are they needed because characters such as percent signs are treated literally.</p>
- <p><strong>File:</strong> 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 <a href="../Scripts.htm#ahk2exe">ahk2exe</a>, which assumes the file is in the script's own directory). Note: <a href="SetWorkingDir.htm">SetWorkingDir</a> has no effect on #Include because #Include is processed before the script begins executing.</p>
- <p><strong>Directory:</strong> Specify a directory instead of a file to change the working directory used by all subsequent occurrences of #Include and <a href="FileInstall.htm">FileInstall</a>. Note: Changing the working directory in this way does not affect the script's initial working directory when it starts running (<a href="../Variables.htm#WorkingDir">A_WorkingDir</a>). To change that, use <a href="SetWorkingDir.htm">SetWorkingDir</a> at the top of the script.</p></dd>
- <dt>LibName</dt>
- <dd><p><span class="ver">[AHK_L 57+]:</span> A library file or function name. For example, <code>#include <lib></code> and <code>#include <lib_func></code> would both include lib.ahk from one of the <a href="../Functions.htm#lib">function library folders</a>.</p></dd>
- </dl>
- <h3>Remarks</h3>
- <p>A script behaves as though the included file's contents are physically present at the exact position of the #Include directive (as though a copy-and-paste were done from the included file). Consequently, it generally cannot merge two isolated scripts together into one functioning script (to achieve that, see <a href="http://www.autohotkey.com/forum/topic18545.html">www.autohotkey.com/forum/topic18545.html</a>).</p>
- <p>#Include ensures that <em>FileName</em> is included only once, even if multiple inclusions are encountered for it. By contrast, #IncludeAgain allows multiple inclusions of the same file, while being the same as #Include in all other respects.</p>
- <p>The <em>FileName</em> parameter may optionally be preceded by *i and a single space, which causes the program to ignore any failure to read the included file. For example: <code>#Include *i SpecialOptions.ahk</code>. This option should be used only when the included file's contents are not essential to the main script's operation.</p>
- <p>Lines displayed in the main window via <a href="ListLines.htm">ListLines</a> or the menu View->Lines are always numbered according to their physical order within their own files. In other words, including a new file will change the line numbering of the main script file by only one line, namely that of the #Include line itself (except for <a href="../Scripts.htm#ahk2exe">compiled scripts</a>, which merge their included files into one big script at the time of compilation).</p>
- <p>#Include is often used to load <a href="../Functions.htm">functions</a> defined in an external file. Unlike subroutine labels, <a href="../Functions.htm">functions</a> can be included at the very top of the script without affecting the <a href="../Scripts.htm#auto">auto-execute section</a>.</p>
- <p>Like other # directives, #Include cannot be executed conditionally. In other words, this example would not work:</p>
- <pre>if x = 1
- #Include SomeFile.ahk <em>; This line takes effect regardless of the value of x.</em>
- y = 2 <em>; And this line would belong to the IF above, since # directives cannot belong to IFs.</em></pre>
- <p>Files can be automatically included (i.e. without having to use #Include) by calling a <a href="../Functions.htm#lib">library function</a> by name.</p>
- <p><span class="ver">[v1.1.11+]:</span> Use <code>%A_LineFile%\..</code> to refer to the directory which contains the current file, even if it is not the main script file. For example, <code>#Include %A_LineFile%\..\other.ahk</code>.</p>
- <h3>Related</h3>
- <p><a href="../Functions.htm#lib">Libraries of Functions</a>, <a href="../Functions.htm">Functions</a>, <a href="FileInstall.htm">FileInstall</a></p>
- <h3>Example</h3>
- <pre class="NoIndent">#Include C:\My Documents\Scripts\Utility Subroutines.ahk
- #Include %A_ScriptDir% <em>; Changes the working directory for subsequent #Includes and FileInstalls.</em>
- #Include C:\My Scripts <em>; Same as above but for an explicitly named directory.</em></pre>
- </body>
- </html>