Syntax
SetAttr Filename$, Attribute
Remarks
Sets file attributes for Filename$. In Windows, the attributes correspond to those you can set using the Properties command (File menu) in File Manager Windows 3.x and Windows NT) or the Windows Explorer (Windows 95). For definitions of the attributes, display the Properties dialog box and choose the Help button. On the Macintosh, only the Read Only and Hidden attributes are available (Read Only corresponds to the Locked check box in the Get Info dialog box (File menu) in the Finder). The file whose attributes you want to set must be closed; an error occurs if you try to set an attribute for an open document.
Argument | Explanation |
Filename$ | The path and filename of the file whose attribute you want to set |
Attribute | Specifies the attribute: 0 (zero) Clears all attributes except System 1 Read Only 2 Hidden 4 System (not available on the Macintosh) 32 Archive (not available on the Macintosh) |
Note
Attribute values are additive. For example, to set both the Read Only and Archive attributes, Attribute would be 33 (the sum of 1 and 32). For a way to set the Read Only attribute independently, see the example for this entry. You cannot set the System attribute in combination with the Archive attribute.
Example
This example makes the file C:\TEST\TEST.DOC read-only without affecting the file's other attributes. First, GetAttr() returns the current Attribute value. Then the If conditional uses the MOD operator to determine whether the Attribute value is odd, which means the file's Read Only attribute is already selected. In that case, Word displays a message box. If Attribute is an even value or 0 (zero), the SetAttr instruction sets the Read Only attribute. On the Macintosh, substitute a path and filename such as HD:TEST:TEST DOCUMENT.
attribs = GetAttr("C:\TEST\TEST.DOC") Print attribs If attribs MOD 2 Then MsgBox "File is already read-only." Else SetAttr "C:\TEST\TEST.DOC", 1 End If
See Also
GetAttr()