FileSystemInfo.Attributes Özellik

Tanım

Geçerli dosya veya dizin için öznitelikleri alır veya ayarlar.

public:
 property System::IO::FileAttributes Attributes { System::IO::FileAttributes get(); void set(System::IO::FileAttributes value); };
public System.IO.FileAttributes Attributes { get; set; }
member this.Attributes : System.IO.FileAttributes with get, set
Public Property Attributes As FileAttributes

Özellik Değeri

FileAttributes

FileAttributes geçerli FileSystemInfoöğesinin .

Özel durumlar

Belirtilen dosya yok. Yalnızca özellik değeri ayarlanırken oluşturulur.

Belirtilen yol geçersiz. Örneğin, eşlenmemiş bir sürücüdedir. Yalnızca özellik değeri ayarlanırken oluşturulur.

Çağıranın gerekli izni yok.

Yalnızca .NET Core ve .NET 5+ : Kullanıcı bir öznitelik değeri ayarlamayı dener, ancak yazma izni yoktur.

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

Çağıran geçersiz bir dosya özniteliği ayarlamayı dener.

-veya-

Yalnızca .NET Framework: Kullanıcı bir öznitelik değeri ayarlamayı dener ancak yazma izni yoktur.

Refresh() verileri başlatamıyor.

Örnekler

Aşağıdaki örnekte özelliği gösterilmektedir Attributes . Bu kod örneği, sınıfı için FileSystemInfo sağlanan daha büyük bir örneğin parçasıdır.

static void DisplayFileSystemInfoAttributes(FileSystemInfo^ fsi)
{
    //  Assume that this entry is a file.
    String^ entryType = "File";

    // Determine if entry is really a directory
    if ((fsi->Attributes & FileAttributes::Directory) == FileAttributes::Directory)
    {
        entryType = "Directory";
    }
    //  Show this entry's type, name, and creation date.
    Console::WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi->FullName, fsi->CreationTime);
}
static void DisplayFileSystemInfoAttributes(FileSystemInfo fsi)
{
    //  Assume that this entry is a file.
    string entryType = "File";

    // Determine if entry is really a directory
    if ((fsi.Attributes & FileAttributes.Directory) == FileAttributes.Directory )
    {
        entryType = "Directory";
    }
    //  Show this entry's type, name, and creation date.
    Console.WriteLine("{0} entry {1} was created on {2:D}", entryType, fsi.FullName, fsi.CreationTime);
}
Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo)
    ' Assume that this entry is a file.
    Dim entryType As String = "File"

    ' Determine if this entry is really a directory.
    If (fsi.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
        entryType = "Directory"
    End If

    ' Show this entry's type, name, and creation date.
    Console.WriteLine("{0} entry {1} was created on {2:D}", _
        entryType, fsi.FullName, fsi.CreationTime)
End Sub

Açıklamalar

Nesnenin Attributes geçerli örneği aşağıdaki DirectoryInfo yöntemlerden birinden döndürüldüyse özelliğin FileSystemInfo değeri önceden önbelleğe alınır:

Değere veya diğer FileSystemInfo özelliklere erişildiğinde değer önbelleğe alınabilir. En son değeri almak için yöntemini çağırın Refresh .

Yol son önbelleğe alınmış durumdan itibaren mevcut değilse, dönüş değeri olur (FileAttributes)(-1). FileNotFoundException veya DirectoryNotFoundException yalnızca değer ayarlanırken oluşturulabilir.

Bu özelliğin değeri arşiv, sıkıştırılmış, dizin, gizli, çevrimdışı, salt okunur, sistem ve geçici dosya özniteliği bayraklarının birleşimidir.

Bu değeri ayarladığınızda, birden fazla değer uygulamak için bit düzeyinde OR işlecini (| C# dilinde veya Or Visual Basic'te) kullanın. Özelliğindeki Attributes mevcut değerleri korumak için, özelliğin Attributes değerini atamanıza ekleyin. Örnek:

exampleFile.Attributes = exampleFile.Attributes | FileAttributes.ReadOnly;

Şunlara uygulanır

Ayrıca bkz.