Table of contents
TOC
Collapse the table of content
Expand the table of content

GetAttr Function

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Returns an Integer representing the attributes of a file, directory, or folder. SyntaxGetAttr(pathname) The required pathnameargument is astring expression that specifies a file name. The pathname may include the directory or folder, and the drive. Return Values The value returned by GetAttr is the sum of the following attribute values:

ConstantValueDescription
vbNormal0Normal.
vbReadOnly1Read-only.
vbHidden2Hidden.
vbSystem4System file. Not available on the Macintosh.
vbDirectory16Directory or folder.
vbArchive32File has changed since last backup. Not available on the Macintosh.
vbAlias64Specified file name is an alias. Available only on the Macintosh.

Note These constants are specified by Visual Basic for Applications. The names can be used anywhere in your code in place of the actual values.

Remarks To determine which attributes are set, use the And operator to perform abitwise comparison of the value returned by the GetAttr function and the value of the individual file attribute you want. If the result is not zero, that attribute is set for the named file. For example, the return value of the following And expression is zero if the Archive attribute is not set:

Result = GetAttr(FName) And vbArchive

A nonzero value is returned if the Archive attribute is set.

Example

This example uses the GetAttr function to determine the attributes of a file and directory or folder. On the Macintosh, only the constants vbNormal, vbReadOnly, vbHidden and vbAlias are available.

Dim MyAttr
' Assume file TESTFILE has hidden attribute set.
MyAttr = GetAttr("TESTFILE")    ' Returns 2.

' Returns nonzero if hidden attribute is set on TESTFILE.
Debug.Print MyAttr And vbHidden    

' Assume file TESTFILE has hidden and read-only attributes set.
MyAttr = GetAttr("TESTFILE")    ' Returns 3.

' Returns nonzero if hidden attribute is set on TESTFILE.
Debug.Print MyAttr And (vbHidden + vbReadOnly)    

' Assume MYDIR is a directory or folder.
MyAttr = GetAttr("MYDIR")    ' Returns 16.

© 2018 Microsoft