Syntax
|
GetAttr
(filename$)
|
Description
|
Returns an
Integer
containing the attributes of the specified file.
|
Comments
|
The attribute value returned is the sum of the attributes set for the file. The value of each attribute is as follows:
|
|
Constant
|
Value
|
Includes
|
|
EbNormal
|
0
|
Read-only files, archive files, subdirectories, and files with no attributes.
|
|
EbReadOnly
|
1
|
Read-only files
|
|
EbHidden
|
2
|
Hidden files
|
|
EbSystem
|
4
|
System files
|
|
EbVolume
|
8
|
Volume label
|
|
EbDirectory
|
16
|
DOS subdirectories
|
|
EbArchive
|
32
|
Files that have changed since the last backup
|
|
EbNone
|
64
|
Files with no attributes
|
|
To determine whether a particular attribute is set, you can
And
the values shown above with the value returned by
GetAttr
. If the result is
True
, the attribute is set, as shown below:
Sub Main()
Dim w As Integer
w = GetAttr("sample.txt")
If w And ebReadOnly Then MsgBox "This file is read-only."
End Sub
|
Example
|
This example tests to see whether the file test.dat exists. If it does not, then it creates the file. The file attributes are then retrieved with the GetAttr function, and the result is displayed.
Const crlf = Chr$(13) + Chr$(10)
|
|
Sub Main()
Dim a()
FileList a,"*.*"
Again:
msg1 = ""
r = SelectBox("Attribute Checker","Select File:",a)
If r = -1 Then
End
Else
y% = GetAttr(a(r))
End If
If y% = 0 Then msg1 = msg1 & "This file has no special attributes." & crlf
If y% And ebReadOnly Then msg1 = msg1 & "The read-only bit is set." & crlf
If y% And ebHidden Then msg1 = msg1 & "The hidden bit is set." & crlf
If y% And ebSystem Then msg1 = msg1 & "The system bit is set." & crlf
If y% And ebVolume Then msg1 = msg1 & "The volume bit is set." & crlf
If y% And ebDirectory Then msg1 = msg1 & "The directory bit is set." & crlf
If y% And ebArchive Then msg1 = msg1 & "The archive bit is set."
MsgBox msg1
Goto Again
End Sub
|
See Also
|
SetAttr (statement); FileAttr (function).
|