GetAttr Function


GetAttr Function

Class

Microsoft.VisualBasic.FileSystem

Syntax

     Dim result As FileAttribute = GetAttr(pathname) 


pathname (required; String)

The file or directory from which to obtain the attribute details

Description

The GetAttr function retrieves the current set of attributes for a specific file. The return value is the sum of one or more of the following Microsoft.VisualBasic.FileAttribute enumeration values (each of which has a related intrinsic Visual Basic constant):

Enumeration

Constant

Value

Description

Normal

vbNormal

0

Normal file (the absence of other attributes)

ReadOnly

vbReadOnly

1

Read-only file

Hidden

vbHidden

2

Hidden file

System

vbSystem

4

System file

Directory

vbDirectory

16

Directory or folder

Archive

vbArchive

32

File has changed since last backup


Usage at a Glance

  • pathname can be either an absolute or relative path to a file. It can exist on the local or remote drive and can use the drive-letter or UNC path format.

  • An error occurs if pathname is invalid or cannot be found.

  • You can check if a particular attribute has been set by performing a bitwise And comparison of the GetAttr return value with the attribute constant. 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 

Version Differences

Visual Basic 2005 includes My.Computer.FileSystem.GetDirectoryInfo and My.Computer.FileSystem.GetFileInfo methods that provide access to related functionality.

See Also

SetAttr Procedure




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net