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 _


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


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.


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


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


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.


Namespace: Microsoft.VisualBasic

Module: FileSystem

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

See Also

FileAttr Function | GetAttr Function | ArgumentException Class | FileAttribute Enumeration