File.GetAttributes Yöntem

Tanım

Aşırı Yüklemeler

Name Description
GetAttributes(SafeFileHandle)

ile fileHandleilişkilendirilmiş dosya veya dizinin belirtilen FileAttributes değerini alır.

GetAttributes(String)

FileAttributes Yolundaki dosyanın öğesini alır.

GetAttributes(SafeFileHandle)

Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs

ile fileHandleilişkilendirilmiş dosya veya dizinin belirtilen FileAttributes değerini alır.

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

Parametreler

fileHandle
SafeFileHandle

Özniteliklerin alınacağı dosya veya dizin için A SafeFileHandle .

Döndürülenler

FileAttributes Dosyanın veya dizinin.

Özel durumlar

fileHandle, null'e eşittir.

Çağıranın gerekli izni yok.

Şunlara uygulanır

GetAttributes(String)

Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs
Kaynak:
File.cs

FileAttributes Yolundaki dosyanın öğesini alır.

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

Parametreler

path
String

Dosyanın yolu.

Döndürülenler

FileAttributes Yoldaki dosyanın dosyası.

Özel durumlar

2.1'den eski .NET Framework ve .NET Core sürümleri: path boş, yalnızca boşluk içeriyor veya geçersiz karakterler içeriyor.

Belirtilen yol, dosya adı veya her ikisi de sistem tanımlı uzunluk üst sınırını aşıyor.

path geçersiz biçimde.

path bir dosyayı temsil eder ve eşlenmemiş bir sürücüde olması veya dosyanın bulunamaması gibi geçersizdir.

path bir dizini temsil eder ve eşlenmemiş bir sürücüde olması veya dizin bulunamaması gibi geçersizdir.

Bu dosya başka bir işlem tarafından kullanılıyor.

Çağıranın gerekli izni yok.

Örnekler

Aşağıdaki örnek, ve GetAttributes özniteliklerini bir dosyaya SetAttributesArchive uygulayarak ve Hidden yöntemlerini gösterir.

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

Açıklamalar

parametresinin path göreli veya mutlak yol bilgilerini belirtmesine izin verilir. Göreli yol bilgileri geçerli çalışma dizinine göre yorumlanır. Geçerli çalışma dizinini edinmek için bkz. GetCurrentDirectory.

Yaygın G/Ç görevlerinin listesi için bkz. Ortak G/Ç Görevleri.

Ayrıca bkz.

Şunlara uygulanır