İngilizce dilinde oku

Aracılığıyla paylaş


File.SetAttributes Yöntem

Tanım

Aşırı Yüklemeler

SetAttributes(SafeFileHandle, FileAttributes)

ile fileHandleilişkilendirilmiş dosya veya dizinin belirtilen FileAttributes değerini ayarlar.

SetAttributes(String, FileAttributes)

Belirtilen FileAttributes yolda belirtilen dosyayı ayarlar.

SetAttributes(SafeFileHandle, FileAttributes)

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

ile fileHandleilişkilendirilmiş dosya veya dizinin belirtilen FileAttributes değerini ayarlar.

C#
public static void SetAttributes (Microsoft.Win32.SafeHandles.SafeFileHandle fileHandle, System.IO.FileAttributes fileAttributes);

Parametreler

fileHandle
SafeFileHandle

Ayarlanması gereken dosyaya veya dizine fileAttributes ASafeFileHandle.

fileAttributes
FileAttributes

Numaralandırma değerlerinin bit düzeyinde bir birleşimi.

Özel durumlar

fileHandle, null değeridir.

Çağıranın gerekli izni yok.

Açıklamalar

yöntemini kullanarak SetAttributes(SafeFileHandle, FileAttributes) bir File nesnenin sıkıştırma durumunu değiştirmek mümkün değildir.

Şunlara uygulanır

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

SetAttributes(String, FileAttributes)

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

Belirtilen FileAttributes yolda belirtilen dosyayı ayarlar.

C#
public static void SetAttributes (string path, System.IO.FileAttributes fileAttributes);

Parametreler

path
String

Dosyanın yolu.

fileAttributes
FileAttributes

Numaralandırma değerlerinin bit düzeyinde bir birleşimi.

Özel durumlar

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

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.

Belirtilen yol geçersiz (örneğin, yol eşlenmemiş bir sürücü üzerinde).

Dosya bulunamıyor.

path salt okunur bir dosya belirtti.

-veya-

Bu işlem geçerli platformda desteklenmiyor.

-veya-

path bir dizin belirtti.

-veya-

Ç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. .

ve ReadOnlygibi Hidden bazı dosya öznitelikleri birleştirilebilir. gibi Normaldiğer öznitelikler tek başına kullanılmalıdır.

yöntemini kullanarak SetAttributes bir File nesnenin sıkıştırma durumunu değiştirmek mümkün değildir.

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