Examples: GetFileAttr function

This example creates a file, calls SetFileAttr to set its attributes to Read-Only, System, and Hidden, and then calls GetFileAttr to determine the file attributes.

%Include "lsconst.lss"
Dim fileNum As Integer, attr As Integer
Dim fileName As String, msg As String
fileNum% = FreeFile()
fileName$ = "data.txt"
Open fileName$ For Output As fileNum%
Close fileNum%
SetFileAttr fileName$, ATTR_READONLY + ATTR_SYSTEM + _ ATTR_HIDDEN
attr% = GetFileAttr(fileName$)
If (attr% And ATTR_READONLY) Then
  msg$ = msg$ & " Read-Only "
Else
  msg$ = msg$ & " Normal "
End If
If (attr% And ATTR_HIDDEN)    Then msg$ = msg$ & " Hidden "
If (attr% And ATTR_SYSTEM)    Then msg$ = msg$ & " System "
If (attr% And ATTR_DIRECTORY) Then msg$ = msg$ & " Directory "
Print msg$
SetFileAttr fileName$, ATTR_NORMAL  ' Reset to normal.
Kill fileName$