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 でない場合、その属性は名前付きファイルに対して設定されます。 たとえば、 属性が設定されていない場合、次 And の式の戻り Archive 値は 0 になります。

Result = GetAttr(FName) And vbArchive  

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

適用対象

こちらもご覧ください