FileGetAttrib

Reports whether a file or folder is read-only, hidden, etc.

AttributeString := FileGetAttrib(Filename)

Parameters

Filename

Type: String

If omitted, the current file of the innermost enclosing file loop will be used. Otherwise, specify the name of the target file, which is assumed to be in A_WorkingDir if an absolute path isn't specified. Unlike FileExist and DirExist, this must be a true filename, not a pattern.

Return Value

Type: String

This function returns the attributes of the file or folder. This string is a subset of RASHNDOCTL, where each letter means the following:

Error Handling

An OSError is thrown on failure.

A_LastError is set to the result of the operating system's GetLastError() function.

Remarks

To check if a particular attribute is present in the retrieved string, see example #2 below.

On a related note, to retrieve a file's 8.3 short name, follow this example:

Loop Files, "C:\My Documents\Address List.txt"
    ShortPathName := A_LoopFileShortPath  ; Will yield something similar to C:\MYDOCU~1\ADDRES~1.txt

A similar method can be used to get the long name of an 8.3 short name.

FileExist, DirExist, FileSetAttrib, FileGetTime, FileSetTime, FileGetSize, FileGetVersion, file loop

Examples

Stores the attribute letters of a directory in OutputVar. Note that existing directories always have the attribute letter D.

OutputVar := FileGetAttrib("C:\New Folder")

Checks if the Hidden attribute is present in the retrieved string.

if InStr(FileGetAttrib("C:\My File.txt"), "H")
    MsgBox "The file is hidden."