İngilizce dilinde oku

Aracılığıyla paylaş


File.GetAttributes Yöntem

Tanım

Aşırı Yüklemeler

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

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

C#
public static System.IO.FileAttributes GetAttributes (Microsoft.Win32.SafeHandles.SafeFileHandle fileHandle);

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 değeridir.

Çağıranın gerekli izni yok.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET 7, 8, 9

GetAttributes(String)

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

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

C#
public static System.IO.FileAttributes GetAttributes (string path);

Parametreler

path
String

Dosyanın yolu.

Döndürülenler

FileAttributes Yoldaki dosyanın dosyası.

Özel durumlar

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

Belirtilen yol, dosya adı veya her ikisi birden sistem tarafından tanımlanan en fazla uzunluğu aşıyor.

path geçersiz bir biçimde.

path bir dosyayı temsil eder ve eşlenmemiş bir sürücüde olmak gibi geçersizdir veya dosya bulunamaz.

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

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

Çağıranın gerekli izni yok.

Örnekler

Aşağıdaki örnek, ve SetAttributes özniteliklerini bir dosyaya uygulayarak Archive ve Hidden yöntemlerini gösterirGetAttributes.

C#
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;
    }
}

Açıklamalar

parametresinin path göreli veya mutlak yol bilgilerini belirtmesine izin verilir. Göreli yol bilgisi, 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

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0