# #Include / #IncludeAgain

Causes the script to behave as though the specified file's contents are present at this exact position.

#Include FileOrDirName
#IncludeAgain FileOrDirName

#### Parameters

FileOrDirName | 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). The file name must not contain variable references (except %A_ScriptDir%, %A_AppData%, and %A_AppDataCommon%), double quotes, or wildcards. Escape sequences other than semicolon (`;) must not be used, nor are they needed because characters such as percent signs are treated literally. 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. The directory name must not contain variables other than %A_ScriptDir%, %A_AppData%, and %A_AppDataCommon%. 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.

#### Remarks

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 www.autohotkey.com/forum/topic18545.html).

#Include ensures that FileName 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.

The FileName parameter may optionally be preceded by *i and a single space, which causes the program to ignore any failure to load the included file. For example: #Include *i SpecialOptions.ahk. This option should be used only when the included file's contents are not essential to the main script's operation.

Lines displayed in the main window via ListLines 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 compiled scripts, which merge their included files into one big script at the time of compilation).

#Include is often used to load functions defined in an external file. Unlike subroutine labels, functions can be included at the very top of the script without affecting the auto-execute section.

Like other # directives, #Include cannot be executed conditionally. In other words, this example would not work:

    if x = 1
        #Include SomeFile.ahk  ; This line takes effect regardless of the value of x.
        y = 2  ; And this line would belong to the IF above, since # directives cannot belong to IFs.

Files can be automatically included (i.e. without having to use #Include) by calling a library function by name.

#### Related

Libraries of Functions, Functions, FileInstall

#### Example

    #Include C:\My Documents\Scripts\Utility Subroutines.ahk
    #Include %A_ScriptDir%  ; Changes the working directory for subsequent #Includes and FileInstalls.
    #Include C:\My Scripts  ; Same as above but for an explicitly named directory.