FileSystem.GetAttr 方法
傳回 FileAttribute 值,表示檔案、目錄或資料夾的屬性。My 功能提供比 FileAttribute 更強的檔案 I/O 作業產能和效能。如需詳細資訊,請參閱 My.Computer.FileSystem 物件。
命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)
語法
'宣告
Public Shared Function GetAttr ( _
PathName As String _
) As FileAttribute
'用途
Dim PathName As String
Dim returnValue As FileAttribute
returnValue = FileSystem.GetAttr(PathName)
public static FileAttribute GetAttr (
string PathName
)
public:
static FileAttribute GetAttr (
String^ PathName
)
public static FileAttribute GetAttr (
String PathName
)
public static function GetAttr (
PathName : String
) : FileAttribute
參數
- PathName
必要項。String 運算式,指定檔案、目錄或資料夾的名稱;PathName 可包括目錄或資料夾及磁碟機。
傳回值
值 Normal、常數 vbNormal、描述正常。值 ReadOnly、常數 vbReadOnly、描述唯讀。值 Hidden、常數 vbHidden、描述隱藏。值 System、常數 vbSystem、描述系統檔案。值 Directory、常數 vbDirectory、描述目錄或資料夾。值 Archive、常數 vbArchive、描述檔案在前次備份之後已經有了變更。值 Alias、常數 vbAlias、描述檔案有不同的名稱。
備註
如需詳細資訊,請參閱 Visual Basic 的主題 GetAttr 函式。
若要判斷已設定哪些屬性,請使用 And 運算子,在 GetAttr 函式所傳回的值與您要的個別檔案屬性值之間執行位元 (Bitwise) 比較。如果結果不是零,則會針對具名檔案設定該屬性。例如,如果未設定 Archive 屬性,則下列 And 運算式的傳回值會是零:
Result = GetAttr(FName) And vbArchive
如果已設定 Archive 屬性,則會傳回非零的值。
範例
此範例使用 GetAttr 函式來判斷檔案及目錄或資料夾的屬性。
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
.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。
版本資訊
.NET Framework
支援版本:2.0、1.1、1.0
請參閱
參考
FileSystem 類別
FileSystem 成員
Microsoft.VisualBasic 命名空間
IOException Class
FileNotFoundException Class
其他資源
GetAttr 函式
And 運算子 (Visual Basic)
FileAttr 函式
SetAttr 函式
FileAttribute 列舉型別
Visual Basic 中的檔案、目錄和磁碟機屬性