In general, programs are affected by two kinds of path length limitations:
These limitations are often referred to as "MAX_PATH limitations", after the constant MAX_PATH
, which has the value 260. One character is generally reserved for a null terminator, leaving 259 characters for the actual path.
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:
\\?\
enables it to exceed the usual limit. However, some system functions do not support it (or long paths in general). See Known Limitations for details.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:
dir\file.ext
, \file.ext
and C:file.ext
(note the absence of a slash).\..
and \.
./
with \
and eliminating redundant separators.dir.\file
) or trailing spaces and periods (dir\filename . .
).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:\
).
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.