FileSystem.GetAttr(String) メソッド

定義

ファイル、ディレクトリ、またはフォルダーの属性を表す FileAttribute 値を返します。 My機能を使用すると、FileAttributeよりもファイル I/O 操作の生産性とパフォーマンスが向上します。 詳細については、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 関数によって返される値と、必要な個々のファイル属性の値のビットごとの比較を実行します。 結果が 0 ではない場合、その属性は名付けられたファイルに設定されます。 たとえば、Archive属性が設定されていない場合、次のAnd式の戻り値は 0 になります。

Result = GetAttr(FName) And vbArchive

Archive属性が設定されている場合は、0 以外の値が返されます。

適用対象

こちらもご覧ください