Returns a number representing the attributes of a file, directory or folder.
GetAttr(pathname)
The pathname argument is a string expression that specifies a filename. The pathname may include the directory or folder, and the drive.
The value returned by GetAttr is the sum of the following attribute values:
Value |
Constant |
Description |
0 |
vbNormal |
Normal. |
1 |
vbReadOnly |
Read-only. |
2 |
vbHidden |
Hidden. |
4 |
vbSystem |
System file . |
16 |
vbDirectory |
Directory or folder. |
32 |
vbArchive |
File has changed since last backup . |
Note These constants are specified by Visual Basic for applications. As a result, the names can be used anywhere in your code in place of the actual values.
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.
And Operator, FileAttr Function, SetAttr Statement.
This example uses the GetAttr function to determine the attributes of a file and directory or folder.
' Assume file TESTFILE has hidden attribute set.= GetAttr("TESTFILE") ' Returns 2. ' Returns nonzero if hidden attribute is set on TESTFILE..Print MyAttr And vbHidden ' Assume file TESTFILE has hidden and read-only attributes set.= GetAttr("TESTFILE") ' Returns 3. ' Returns nonzero if hidden attribute is set on TESTFILE..Print MyAttr And (vbHidden + vbReadOnly) ' Assume MYDIR is a directory or folder.= GetAttr("MYDIR") ' Returns 16.