This documentation is archived and is not being maintained.

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.

Smart Device Developer Notes

This function is not supported.

Requirements

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Microsoft Visual Basic .NET Runtime (in MicrosoftVisualBasic.dll)

See Also

FileAttr Function | GetAttr Function | ArgumentException Class | FileAttribute Enumeration

Show: