Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

GetAttr Function

Class

Microsoft. VisualBasic.FileSystem

Yes

Syntax

GetAttr(pathname)
pathname (required; String)

Filename and an optional pathname

Return Value

An integer representing the sum of the following constants or members of the FileAttribute enumeration, which reflect the attributes set for the file:

FileAttribute Enum

Constant

Value

Description

Normal

VbNormal

0

Normal

ReadOnly

VbReadOnly

1

Read-only

Hidden

VbHidden

2

Hidden

System

VbSystem

4

System

Directory

VbDirectory

16

Directory or folder

Archive

VbArchive

32

File has changed since last backup

Description

Determines which attributes have been set for a file or directory

Rules at a Glance

  • pathname may optionally include a directory name and a drive letter, including a network drive. pathname can also follow the UNC format of //machine_ name/drive.

  • You can check if a particular attribute has been set by performing a bitwise comparison of the GetAttr return value and the value of the attribute constant using the And operator. A nonzero result means that the particular attribute has been set; conversely, a zero value indicates that the attribute has not been set. For example:

    If (GetAttr(myfile.txt) And VbReadOnly) = 0 then
        Msgbox "The file is Read-Write"
    Else
        MsgBox "The file is Read-Only"
    End If

Programming Tips and Gotchas

If pathname is invalid, a FileNotFoundException exception is generated.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata