FileSystem.GetAttr(String) 메서드

정의

파일, 디렉터리 또는 폴더의 특성을 나타내는 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 값과 원하는 개별 파일 특성의 값을 비트 비교합니다. 결과가 0이 아니면 명명된 파일에 대해 해당 특성이 설정됩니다. 예를 들어 특성이 설정되지 않은 경우 Archive 다음 And 식의 반환 값은 0입니다.

Result = GetAttr(FName) And vbArchive  

특성이 설정된 경우 0이 Archive 아닌 값이 반환됩니다.

적용 대상

추가 정보