SetAttr Function
Sets attribute information for a file.
The My feature gives you greater productivity and performance in file I/O operations than SetAttr. For more information, see My.Computer.FileSystem Object.
Public Sub SetAttr( _
ByVal PathName As String, _
ByVal Attributes As FileAttribute _
)
Parameters
PathName
Required. String expression that specifies a file name. PathName can 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
Exception type |
Error number |
Condition |
---|---|---|
PathName invalid or does not exist. |
||
Attribute type is invalid. |
See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.
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.
' Set hidden attribute.
SetAttr("TESTFILE", vbHidden)
' Set hidden and read-only attributes.
SetAttr("TESTFILE", vbHidden Or vbReadOnly)
Smart Device Developer Notes
This function is not supported.
Requirements
Namespace: Microsoft.VisualBasic
**Module:**FileSystem
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)