GetAttr Function

Description

Returns a number representing the attributes of a file, directory or folder, or volume label.

Syntax

GetAttr(pathname)

The pathname named argument is a string expression that specifies a file name — may include directory or folder, and drive.

Return Values

The value returned by GetAttr is the sum of the following attribute values:

Value

Constant

File Attribute

0

vbNormal

Normal.

1

vbReadonly

Read-only.

2

vbHidden

Hidden.

4

vbSystem

System file — not available on the Macintosh.

8

vbVolume

Volume label — not available on the Macintosh.

16

vbDirectory

Directory or folder.

32

vbArchive

File has changed since last backup — not available on the Macintosh.


Note

These constants are specified by Visual Basic. As a result, 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 a bit-wise 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.

See Also

FileAttr Function, SetAttr Statement.

Example

This example uses the GetAttr statement to determine the attributes of a file and directory or folder.


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

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

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