File.GetAttributes 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| GetAttributes(SafeFileHandle) |
에 연결된 |
| GetAttributes(String) |
경로에 FileAttributes 있는 파일의 값을 가져옵니다. |
GetAttributes(SafeFileHandle)
- Source:
- File.cs
- Source:
- File.cs
- Source:
- File.cs
- Source:
- File.cs
- Source:
- File.cs
에 연결된 fileHandle파일 또는 디렉터리의 지정된 FileAttributes 값을 가져옵니다.
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 특성을 검색할 파일 또는 디렉터리에 대한 A입니다.
반품
FileAttributes 파일 또는 디렉터리의
예외
fileHandle은 null입니다.
호출자에게 필요한 권한이 없습니다.
적용 대상
GetAttributes(String)
- Source:
- File.cs
- Source:
- File.cs
- 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 경로에 있는 파일의 파일입니다.
예외
.NET Framework 및 .NET Core 버전 2.1 이전: path 비어 있거나 공백만 포함하거나 잘못된 문자를 포함합니다.
지정된 경로, 파일 이름 또는 둘 다 시스템 정의 최대 길이를 초과합니다.
path 가 잘못된 형식입니다.
path 는 파일을 나타내며 매핑되지 않은 드라이브에 있는 것과 같이 유효하지 않거나 파일을 찾을 수 없습니다.
path 는 디렉터리를 나타내며 매핑되지 않은 드라이브에 있는 것과 같이 유효하지 않거나 디렉터리를 찾을 수 없습니다.
이 파일은 다른 프로세스에서 사용되고 있습니다.
호출자에게 필요한 권한이 없습니다.
예제
다음 예제에서는 파일 및 GetAttributes 특성을 적용하여 SetAttributes 메서드와 Archive 메서드를 보여 Hidden 줍니다.
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 작업을 참조하세요.