Reading and Writing File Attributes

Discussed in this topic: fd.getattributes, fd.setattributes.

You can set initial file attributes right when creating a new file. To read existing file attributes, use the fd.getattributes method:

'this example ignores potential error conditions
Dim s As String
s=fd.getattributes("File1.dat") 'get the attributes for this file
If instr(1,s,"R",1)=0 Then 'delete the file only if there is no 'R' in the attributes
End If

You can set new (change) attributes with the fd.setattributes method:

If fd.setattributes("File1.dat", "D")<>PL_FD_STATUS_OK Then 'the attribute string will now consist of a single 'D'
   'some problem
End If

Remember that the file name and the attributes share the same 56-byte string in the file record table of the flash disk. Therefore, the maximum length of the attributes is limited to 56-length_of_the_file_name - 1. This "-1" accounts for the space character that separates the file name from the attributes.

Attempting to perform fd.getattributes or fd.setattributes on a file that does not exist will generate the 9 — PL_FD_STATUS_NOT_FOUND error.

The fd.setattributes method makes changes to the sectors of the flash disk. For the highest possible reliability, use disk transactions when invoking it.