Includes a file in the current script.
#include "[path\]filename"
#include <filename>
filename | The filename of the current script to include. Path is optional. This must be a string--it cannot be a variable. If "..." is used, the filename is taken to be relative to the current script. If <...> is used the filename is taken to be relative to include library directory (usually C:\Program Files\AutoIt3\Include). The include library contains many pre-written user-functions for you to use! |
Other scripts can be included into an Autoit script using the #include command - these can be in either .au3 or .a3x format. The content of the included file is inserted into the script at the point of the #include command - in most cases this is the beginning of the script so that any variable or constant declarations within the included text are available to the rest of the script.
If you include the same file containing a user defined function more than once you will get a "Duplicate function" error. When writing an include file that may be used in this way, make sure that the firstline contains #include-once to prevent that file from being included more than once.
There is a special registry value that can be created at "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt" called "Include". It should be a REG_SZ (string) value. The contents of this value are a semi-colon delimited list of directories that should be searched for files when resolving #include's in addition to the standard locations.
The search order used by AutoIt depends on which form of #include you use. The tables below show the order directories are searched using both forms.
Using #include <>
Standard library | The path of the currently running interpreter with "\Include" appended is searched. |
User-defined libraries | The registry value mentioned above is read and each directory is searched in the order they appear in. |
Script directory | The directory of the currently executing script. |
Script directory | The directory of the currently executing script. |
User-defined libraries | The registry value mentioned above is read and each directory is searched in the reverse order they appear in. |
Standard library | The path of the currently running interpreter with "\Include" appended is searched. |