FileSystemInfo.Attributes 속성

정의

현재 파일 또는 디렉터리의 특성을 가져오거나 설정합니다.

public:
 property System::IO::FileAttributes Attributes { System::IO::FileAttributes get(); void set(System::IO::FileAttributes value); };
public System.IO.FileAttributes Attributes { get; set; }
member this.Attributes : System.IO.FileAttributes with get, set
Public Property Attributes As FileAttributes

속성 값

현재 FileAttributesFileSystemInfo입니다.

예외

지정된 파일이 없습니다. 속성 값을 설정할 때만 throw됩니다.

지정한 경로가 잘못되었습니다. 예를 들어, 매핑되지 않은 드라이브에 있습니다. 속성 값을 설정할 때만 throw됩니다.

호출자에게 필요한 권한이 없습니다.

.NET Core 및 .NET 5 이상만 해당: 사용자가 특성 값을 설정하려고 하지만 쓰기 권한이 없습니다.

지정된 경로, 파일 이름 또는 둘 다가 시스템에서 정의한 최대 길이를 초과합니다.

호출자가 잘못된 파일 특성을 설정하려고 한 경우

또는

.NET Framework만 해당: 사용자가 특성 값을 설정하려고 하지만 쓰기 권한이 없습니다.

Refresh()가 데이터를 초기화할 수 없는 경우

예제

다음 예제는 Attributes 속성입니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 FileSystemInfo 클래스입니다.

static void DisplayFileSystemInfoAttributes(FileSystemInfo^ fsi)
{
    //  Assume that this entry is a file.
    String^ entryType = "File";

    // Determine if entry is really a directory
    if ((fsi->Attributes & FileAttributes::Directory) == FileAttributes::Directory)
    {
        entryType = "Directory";
    }
    //  Show this entry's type, name, and creation date.
    Console::WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi->FullName, fsi->CreationTime);
}
static void DisplayFileSystemInfoAttributes(FileSystemInfo fsi)
{
    //  Assume that this entry is a file.
    string entryType = "File";

    // Determine if entry is really a directory
    if ((fsi.Attributes & FileAttributes.Directory) == FileAttributes.Directory )
    {
        entryType = "Directory";
    }
    //  Show this entry's type, name, and creation date.
    Console.WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi.FullName, fsi.CreationTime);
}
Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo)
    ' Assume that this entry is a file.
    Dim entryType As String = "File"

    ' Determine if this entry is really a directory.
    If (fsi.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
        entryType = "Directory"
    End If

    ' Show this entry's type, name, and creation date.
    Console.WriteLine("{0} entry {1} was created on {2:D}", _
        entryType, fsi.FullName, fsi.CreationTime)
End Sub

설명

개체의 Attributes 현재 instance 다음 DirectoryInfo 메서드 중 하나에서 반환된 경우 속성 값 FileSystemInfo 이 미리 캐시됩니다.

값 자체 또는 다른 FileSystemInfo 속성에 액세스할 때 값이 캐시될 수 있습니다. 최신 값을 얻으려면 메서드를 호출합니다 Refresh .

경로가 마지막 캐시된 상태로 존재하지 않는 경우 반환 값은 입니다 (FileAttributes)(-1). FileNotFoundException 또는 DirectoryNotFoundException 는 값을 설정할 때만 throw될 수 있습니다.

이 속성의 값은 보관, 압축, 디렉터리, 숨겨진, 오프라인, 읽기 전용, 시스템 및 임시 파일 특성 플래그의 조합입니다.

이 값을 설정할 때 비트 OR 연산자(| C# 또는 Or Visual Basic의 경우)를 사용하여 둘 이상의 값을 적용합니다. 속성의 Attributes 기존 값을 유지하려면 할당에 속성 값을 Attributes 포함합니다. 예를 들면 다음과 같습니다.

exampleFile.Attributes = exampleFile.Attributes | FileAttributes.ReadOnly;

적용 대상

추가 정보