File.GetAttributes 메서드

정의

오버로드

GetAttributes(SafeFileHandle)

와 연결된 파일 또는 디렉터리에 지정된 FileAttributesfileHandle가져옵니다.

GetAttributes(String)

경로에 있는 파일의 FileAttributes를 가져옵니다.

GetAttributes(SafeFileHandle)

Source:
File.cs
Source:
File.cs
Source:
File.cs

와 연결된 파일 또는 디렉터리에 지정된 FileAttributesfileHandle가져옵니다.

public:
 static System::IO::FileAttributes GetAttributes(Microsoft::Win32::SafeHandles::SafeFileHandle ^ fileHandle);
public static System.IO.FileAttributes GetAttributes (Microsoft.Win32.SafeHandles.SafeFileHandle fileHandle);
static member GetAttributes : Microsoft.Win32.SafeHandles.SafeFileHandle -> System.IO.FileAttributes
Public Shared Function GetAttributes (fileHandle As SafeFileHandle) As FileAttributes

매개 변수

fileHandle
SafeFileHandle

SafeFileHandle 특성을 검색할 파일 또는 디렉터리에 대한 입니다.

반환

FileAttributes 파일 또는 디렉터리의 입니다.

예외

fileHandle이(가) null인 경우

호출자에게 필요한 권한이 없는 경우

적용 대상

GetAttributes(String)

Source:
File.cs
Source:
File.cs
Source:
File.cs

경로에 있는 파일의 FileAttributes를 가져옵니다.

public:
 static System::IO::FileAttributes GetAttributes(System::String ^ path);
public static System.IO.FileAttributes GetAttributes (string path);
static member GetAttributes : string -> System.IO.FileAttributes
Public Shared Function GetAttributes (path As String) As FileAttributes

매개 변수

path
String

파일의 경로입니다.

반환

경로에 있는 파일의 FileAttributes입니다.

예외

2.1보다 오래된 .NET Framework 및 .NET Core 버전: path 가 비어 있거나 공백만 포함하거나 잘못된 문자를 포함합니다.

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

path의 형식이 잘못되었습니다.

path가 매핑되지 않은 드라이브에 있는 파일과 같이 올바르지 않은 파일을 나타내거나 파일을 찾을 수 없습니다.

path가 매핑되지 않은 드라이브에 있는 디렉터와 같이 올바르지 않은 디렉터리를 나타내거나 디렉터리를 찾을 수 없습니다.

이 파일을 다른 프로세서에서 사용 중입니다.

호출자에게 필요한 권한이 없는 경우

예제

다음 예에서는 및 특성을 파일에 적용하여 ArchiveSetAttributesHidden 메서드를 보여 GetAttributes 줍니다.

using namespace System;
using namespace System::IO;
using namespace System::Text;
int main()
{
   String^ path = "c:\\temp\\MyTest.txt";
   
   // Create the file if it does not exist.
   if (  !File::Exists( path ) )
   {
      File::Create( path );
   }

   if ( (File::GetAttributes( path ) & FileAttributes::Hidden) == FileAttributes::Hidden )
   {
      
      // Show the file.
      File::SetAttributes(path, File::GetAttributes( path ) & ~FileAttributes::Hidden);
      Console::WriteLine( "The {0} file is no longer hidden.", path );
   }
   else
   {
      
      // Hide the file.
      File::SetAttributes( path, static_cast<FileAttributes>(File::GetAttributes( path ) | FileAttributes::Hidden) );
      Console::WriteLine( "The {0} file is now hidden.", path );
   }
}
using System;
using System.IO;
using System.Text;

class Test
{
    public static void Main()
    {
        string path = @"c:\temp\MyTest.txt";

        // Create the file if it does not exist.
        if (!File.Exists(path))
        {
            File.Create(path);
        }

        FileAttributes attributes = File.GetAttributes(path);

        if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
        {
            // Show the file.
            attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
            File.SetAttributes(path, attributes);
            Console.WriteLine("The {0} file is no longer hidden.", path);
        }
        else
        {
            // Hide the file.
            File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
            Console.WriteLine("The {0} file is now hidden.", path);
        }
    }

    private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
    {
        return attributes & ~attributesToRemove;
    }
}
open System.IO
open System.Text

let removeAttribute attributes attributesToRemove = attributes &&& ~~~attributesToRemove

let path = @"c:\temp\MyTest.txt"

// Create the file if it does not exist.
if File.Exists path |> not then
    File.Create path |> ignore

let attributes = File.GetAttributes path

if attributes &&& FileAttributes.Hidden = FileAttributes.Hidden then
    // Show the file.
    let attributes =
        removeAttribute attributes FileAttributes.Hidden

    File.SetAttributes(path, attributes)
    printfn $"The {path} file is no longer hidden."
else
    // Hide the file.
    File.SetAttributes(path, File.GetAttributes path ||| FileAttributes.Hidden)
    printfn $"The {path} file is now hidden."
Imports System.IO
Imports System.Text

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"

        ' Create the file if it does not exist.
        If File.Exists(path) = False Then
            File.Create(path)
        End If

        Dim attributes As FileAttributes
        attributes = File.GetAttributes(path)

        If (attributes And FileAttributes.Hidden) = FileAttributes.Hidden Then
            ' Show the file.
            attributes = RemoveAttribute(attributes, FileAttributes.Hidden)
            File.SetAttributes(path, attributes)
            Console.WriteLine("The {0} file is no longer hidden.", path)
        Else
            ' Hide the file.
            File.SetAttributes(path, File.GetAttributes(path) Or FileAttributes.Hidden)
            Console.WriteLine("The {0} file is now hidden.", path)
        End If
    End Sub

    Public Shared Function RemoveAttribute(ByVal attributes As FileAttributes, ByVal attributesToRemove As FileAttributes) As FileAttributes
        Return attributes And (Not attributesToRemove)
    End Function
End Class

설명

path 매개 변수는 상대 경로 또는 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리를 기준으로 해석됩니다. 현재 작업 디렉터리를 가져오려면 를 참조하세요 GetCurrentDirectory.

일반적인 I/O 작업 목록은 일반적인 I/O 작업을 참조하세요.

추가 정보

적용 대상