Visual Basic Language Reference  

SetAttr Function

Sets attribute information for a file.

Public Sub SetAttr( _
   ByVal PathName As String, _
   ByVal Attributes As FileAttribute _
)

Parameters

PathName
Required. String expression that specifies a file name. PathName may include directory or folder, and drive.
Attributes
Required. Constant or numeric expression, whose sum specifies file attributes.

Settings

The Attributes argument enumeration values are:

Value Constant Description
Normal VbNormal Normal (default).
ReadOnly VbReadOnly Read-only.
Hidden VbHidden Hidden.
System VbSystem System file.
Volume VbVolume Volume label
Directory VbDirectory Directory or folder.
Archive VbArchive File has changed since last backup.
Alias VbAlias File has a different name.
Note   These enumerations are specified by the Visual Basic language. The names can be used anywhere in your code in place of the actual values.

Exceptions/Errors

Exception type Error number Condition
ArgumentException 52 PathName invalid or does not exist.
ArgumentException 5 Attribute type is invalid.

Remarks

A run-time error occurs if you try to set the attributes of an open file.

Example

This example uses the SetAttr function to set attributes for a file.

SetAttr("TESTFILE", vbHidden)   ' Set hidden attribute.
SetAttr("TESTFILE", vbHidden Or vbReadOnly)   ' Set hidden and read-only
   ' attributes.

See Also

FileAttr Function | GetAttr Function | ArgumentException