SetAttr

Sets attribute information for a file.

Syntax: SetAttr pathname, attributes

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

Settings

The attributes settings are:

Constant Value Description
vbNormal 0 Normal (default).
vbReadOnly 1 Read-only.
vbHidden 2 Hidden.
vbSystem 4 System file.
vbArchive 32 File has changed since last backup.

SetAttr passes attributes to Windows as it is, so it sets any attribute Windows lets a program set, such as 256 (temporary) or 8192 (not indexed), and raises an error where Windows refuses. A bit that Windows ignores, such as vbDirectory (16) on a file, is left out.

Note

VB6 and 64-bit VBA raise error 5, Invalid procedure call or argument, for attributes that are not a sum of the values in the table, and for vbDirectory on a folder.

SetAttr sets the attributes of a file that is open, whatever mode it is open in, without an error.

Common Errors

Error When
-2147467259 (&H80004005), Unspecified error no file or folder has the name pathname, which includes one in a folder or drive that does not exist, a zero-length string, and a name with a character a name cannot hold
pathname holds a wildcard
94 (&H5E), Invalid use of Null pathname or attributes is Null

Note BETA 1034

When no file or folder has the name pathname, which includes one in a folder or drive that does not exist, a zero-length string, and a name with a character a name cannot hold, VB6 and 64-bit VBA raise error 53 (&H35), File not found, instead.

Note BETA 1034

When pathname holds a wildcard, VB6 and 64-bit VBA raise error 52 (&H34), Bad file name or number, instead.

Note BETA 1034

When the file is open for Output, Append, Binary or Random, VB6 and 64-bit VBA raise error 55 (&H37), File already open; twinBASIC raises none.

Example

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

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

See Also