Written by

Web Developer
Question Mack Altman · Aug 3, 2017

Retrieving attributes from Library.File()

In reviewing the documentation found here, it states that there is an Attributes property. Since this is an array, I was wondering how I would go about traversing through the array to review what attributes are available on the file.

Comments

Timothy Leavitt · Aug 3, 2017

When working with files, it's much better to use %Stream classes rather than an instance of %Library.File. If you're looking to get the attributes of a file/directory, the Attributes method in %Library.File is probably your best option. According to the class reference (which has all the details), it returns a combination of bits, the meaning of which varies depending on the operating system. This is kind of ugly, but here's an example on Windows:

USER>set attributes = ##class(%Library.File).Attributes("C:\Users\tleavitt\AppData\")
 
USER>w attributes
8210

USER>for i=0:1:16 { w:$zboolean(attributes,2**i,1) 2**i,! }
2
16
8192

According to the class reference, this is a directory (16) that is hidden (2) and not indexed (8192).

%Library.File also has some OS-independent classmethods that may be easier to use for simpler things like seeing if a file is read-only.

0