FileGetAttrib

AutoHotkey GUI

FileGetAttrib

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

FileGetAttrib, OutputVar , Filename

Parameters

OutputVar

The name of the variable in which to store the retrieved text.

Filename

The name of the target file, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. If omitted, the current file of the innermost enclosing File-Loop will be used instead. Unlike FileExist, this must be a true filename, not a pattern.

ErrorLevel

[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

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

Remarks

The string returned will contain a subset of the letters in the string "RASHNDOCT":

R = READONLY
A = ARCHIVE
S = SYSTEM
H = HIDDEN
N = NORMAL
D = DIRECTORY
O = OFFLINE
C = COMPRESSED
T = TEMPORARY


To check if a particular attribute is present in the retrieved string, following this example:

FileGetAttrib, Attributes, C:\My File.txt
IfInString, Attributes, H
    MsgBox The file is hidden.

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

Loop, 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.

Related

FileExist(), FileSetAttrib, FileGetTime, FileSetTime, FileGetSize, FileGetVersion, File-loop

Example

FileGetAttrib, OutputVar, C:\New Folder