O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

SetAttr Procedure

Class

Microsoft.VisualBasic.FileSystem

Syntax

SetAttr(pathname, attributes)
pathname (required; String)

The name of the file or directory whose attributes are to be set

attributes (required; FileAttribute enumeration)

Numeric expression, FileAttribute enumerated constant, or global VB constant specifying the attributes

Description

Changes the attribute properties of a file

Rules at a Glance

  • You can use any sum of the following constants to set the attributes of a file:

    Constant

    Value

    Description

    VbNormal

    0

    Normal

    VbReadOnly

    1

    Read-only

    VbHidden

    2

    Hidden

    VbSystem

    4

    System

    VbArchive

    32

    File has changed since last backup

    Each global constant has a corresponding constant in the FileAttribute enumeration. For example, vbNormal is identical to FileAttribute.Normal. The file-attribute constants vbDirectory, vbAlias, and vbVolume cannot be used when assigning attributes.

  • File-attributes constants can be Ored to set more than one attribute at the same time. For example:

    SetAttr "SysFile.Dat", FileAttribute.System Or FileAttribute.Hidden
  • pathname can include a drive letter. If a drive letter is not included in pathname, the current drive is assumed. The file path can be either a fully qualified path or a relative path from the current directory.

  • pathname can include a folder name. If the folder name is not included in pathname, the current folder is assumed.

  • Attempting to set the attributes of an open file will generate a runtime error.

Example ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required