PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/commands/_Include.htm

https://github.com/fincs/AutoHotkey_L-Docs
HTML | 55 lines | 47 code | 8 blank | 0 comment | 0 complexity | 79ae65cc03adf4eab0c07ea8b0dfeaa3 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>#Include</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  8. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  9. <script src="../static/jquery.js" type="text/javascript"></script>
  10. <script src="../static/tree.jquery.js" type="text/javascript"></script>
  11. <script src="../static/content.js" type="text/javascript"></script>
  12. </head>
  13. <body>
  14. <h1>#Include / #IncludeAgain</h1>
  15. <p>Causes the script to behave as though the specified file's contents are present at this exact position.</p>
  16. <pre class="Syntax">#Include FileOrDirName
  17. #Include &lt;LibName&gt;
  18. #IncludeAgain FileOrDirName</pre>
  19. <h3>Parameters</h3>
  20. <dl>
  21. <dt>FileOrDirName</dt>
  22. <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>
  23. <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>
  24. <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>
  25. <dt>LibName</dt>
  26. <dd><p><span class="ver">[AHK_L 57+]:</span> A library file or function name. For example, <code>#include &lt;lib&gt;</code> and <code>#include &lt;lib_func&gt;</code> would both include lib.ahk from one of the <a href="../Functions.htm#lib">function library folders</a>.</p></dd>
  27. </dl>
  28. <h3>Remarks</h3>
  29. <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>
  30. <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>
  31. <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>
  32. <p>Lines displayed in the main window via <a href="ListLines.htm">ListLines</a> or the menu View-&gt;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>
  33. <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>
  34. <p>Like other # directives, #Include cannot be executed conditionally. In other words, this example would not work:</p>
  35. <pre>if x = 1
  36. #Include SomeFile.ahk <em>; This line takes effect regardless of the value of x.</em>
  37. y = 2 <em>; And this line would belong to the IF above, since # directives cannot belong to IFs.</em></pre>
  38. <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>
  39. <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>
  40. <h3>Related</h3>
  41. <p><a href="../Functions.htm#lib">Libraries of Functions</a>, <a href="../Functions.htm">Functions</a>, <a href="FileInstall.htm">FileInstall</a></p>
  42. <h3>Example</h3>
  43. <pre class="NoIndent">#Include C:\My Documents\Scripts\Utility Subroutines.ahk
  44. #Include %A_ScriptDir% <em>; Changes the working directory for subsequent #Includes and FileInstalls.</em>
  45. #Include C:\My Scripts <em>; Same as above but for an explicitly named directory.</em></pre>
  46. </body>
  47. </html>