Checks for the existence of a folder and returns its attributes.
AttributeString := DirExist(FilePattern)
The path, folder name, or file pattern to check. FilePattern is assumed to be in A_WorkingDir if an absolute path isn't specified.
This function returns the attributes of the first matching folder. This string is a subset of
ASHDOC, where each letter means the following:
Since this function only checks for the existence of a folder, "D" is always present in the return value. If no folder is found, an empty string is returned.
Note that searches such as
DirExist("FolderWithFilesAndSubfolders\*") only tells you whether a folder exists. If you want to check for the existence of files and folders, use FileExist instead.
Unlike FileGetAttrib, DirExist supports wildcard patterns and always returns a non-empty value if a matching folder exists.
Since an empty string is seen as "false", the function's return value can always be used as a quasi-boolean value. For example, the statement
if DirExist("C:\MyFolder") would be true if the folder exists and false otherwise.
Since FilePattern may contain wildcards, DirExist may be unsuitable for validating a folder path which is to be used with another function or program. For example,
DirExist("Program*") may return attributes even though "Program*" is not a valid folder name. In such cases, FileGetAttrib is preferred.
FileExist, FileGetAttrib, File-loops
if DirExist("C:\Program*") MsgBox "At least one program folder exists." if !DirExist("C:\Temp") MsgBox "The target folder does not exist."
#2: The following example shows how to check the folder for a particular attribute:
if InStr(DirExist("C:\System Volume Information"), "H") MsgBox "The folder is hidden."