Long Paths [v1.1.31+]

In general, programs are affected by two kinds of path length limitations:

  1. Functions provided by the operating system generally limit paths to 259 characters, with some exceptions.
  2. Code for dealing with paths within the program may rely on the first limitation to simplify the code, effectively placing another 259 character limitation.

These limitations are often referred to as "MAX_PATH limitations", after the constant MAX_PATH, which has the value 260. This allows for the drive letter, colon and slash (C:\), a single file or directory name at maximum length (255 characters), and a null terminator.

AutoHotkey [v1.1.31+] (excluding ANSI versions) removes the second kind in most cases, which enables the script to work around the first kind. There are two ways to do this:

Long Path Prefix

If supported by the underlying system function, the \\?\ prefix -- for example, in \\?\C:\My Folder -- increases the limit to 32,767 characters. However, it does this by skipping path normalization. Some elements of the path which would normally be removed or altered by normalization instead become part of the file's actual path. Care must be taken as this can allow the creation of paths that "normal" programs cannot access.

In particular, normalization:

A path can be normalized explicitly by passing it to GetFullPathName via the function defined below, before applying the prefix. For example:

MsgBox % "\\?\" NormalizePath("..\file.ext")
NormalizePath(path) {
    cc := DllCall("GetFullPathName", "str", path, "uint", 0, "ptr", 0, "ptr", 0, "uint")
    VarSetCapacity(buf, cc*2)
    DllCall("GetFullPathName", "str", path, "uint", cc, "str", buf, "ptr", 0)
    return buf

A path with the \\?\ prefix can also be normalized by this function. However, in that case the working directory is never used, and the root is \\?\ (for example, \\?\C:\.. resolves to \\?\ whereas C:\.. resolves to C:\).

Known Limitations

ANSI versions of AutoHotkey do not support long paths.

Even when the path itself is not limited to 259 characters, each component (file or directory name) cannot exceed the hard limit imposed by the file system (usually 255 characters).

These do not support long paths due to limitations of the underlying system function(s):

SetWorkingDir and A_WorkingDir support long paths only when Windows 10 long path awareness is enabled, since the \\?\ prefix cannot be used. If the working directory exceeds MAX_PATH, it becomes impossible to launch programs with Run. These limitations are imposed by the OS.

It does not appear to be possible to run an executable with a full path which exceeds MAX_PATH. That being the case, it would not be possible to fully test any changes aimed at supporting longer executable paths. Therefore, MAX_PATH limits have been left in place for the following:

Long #Include paths shown in error messages may be truncated arbitrarily.