This documentation is archived and is not being maintained.

FileSystem.GetAttr Method

Returns a FileAttribute value representing the attributes of a file, directory, or folder. The My feature gives you greater productivity and performance in file I/O operations than FileAttribute. For more information, see My.Computer.FileSystem Object.

Namespace: Microsoft.VisualBasic
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public static FileAttribute GetAttr (
	string PathName
)
public static FileAttribute GetAttr (
	String PathName
)
public static function GetAttr (
	PathName : String
) : FileAttribute

Parameters

PathName

Required. String expression that specifies a file, directory, or folder name. PathName can include the directory or folder, and the drive.

Return Value

Value Normal,Constant vbNormal,Description normal. Value ReadOnly,Constant vbReadOnly,Description read-only. Value Hidden,Constant vbHidden,Description hidden. Value System, Constant vbSystem,Description system file. Value Directory,Constant vbDirectory, Description directory or folder. Value Archive,Constant vbArchive,Description file has changed since last backup. Value Alias,Constant vbAlias,Description file has a different name.

For more detailed information, see the Visual Basic topic GetAttr Function.

To determine which attributes are set, use the And operator to perform a bitwise comparison of the value returned by the GetAttr function and the value of the individual file attribute you want. If the result is not zero, that attribute is set for the named file. For example, the return value of the following And expression is zero if the Archive attribute is not set:

Result = GetAttr(FName) And vbArchive

A nonzero value is returned if the Archive attribute is set.

This example uses the GetAttr function to determine the attributes of a file and directory or folder.

Dim MyAttr As FileAttribute
' Assume file TESTFILE is normal and readonly.
MyAttr = GetAttr("C:\TESTFILE.txt")   ' Returns vbNormal.

' Test for normal.
If (MyAttr And FileAttribute.Normal) = FileAttribute.Normal Then
   MsgBox("This file is normal.")
End If

' Test for normal and readonly.
Dim normalReadonly As FileAttribute
normalReadonly = FileAttribute.Normal Or FileAttribute.ReadOnly
If (MyAttr And normalReadonly) = normalReadonly Then
   MsgBox("This file is normal and readonly.")
End If

' Assume MYDIR is a directory or folder.
MyAttr = GetAttr("C:\MYDIR")
If (MyAttr And FileAttribute.Directory) = FileAttribute.Directory Then
   MsgBox("MYDIR is a directory")
End If

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: