FileSystem.GetAttr(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳 FileAttribute 一個代表檔案、目錄或資料夾屬性的值。 這個 My 功能能讓你在檔案 I/O 操作 FileAttribute中提升生產力和效能。 如需詳細資訊,請參閱FileSystem。
public:
static Microsoft::VisualBasic::FileAttribute GetAttr(System::String ^ PathName);
public static Microsoft.VisualBasic.FileAttribute GetAttr(string PathName);
static member GetAttr : string -> Microsoft.VisualBasic.FileAttribute
Public Function GetAttr (PathName As String) As FileAttribute
參數
- PathName
- String
必須的。 一個字串表達式,用來指定檔案、目錄或資料夾名稱。
PathName 可以包含目錄或資料夾,以及磁碟機。
傳回
列舉值的位元組合。
例外狀況
Pathname 無效或包含萬用字元。
目標檔案不存在。
範例
此範例使用函 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
備註
要判斷設定了哪些屬性,請使用 And 運算子對函式回傳 GetAttr 的值與你想要的檔案屬性值進行位元比較。 如果結果不是零,該屬性會被設定為該命名檔案。 例如,若Archive未設定屬性,以下And運算式的回傳值為零:
Result = GetAttr(FName) And vbArchive
若設定屬性 Archive ,則回傳非零值。