FileSystemInfo.Attributes Propriedade
Definição
Obtém ou define os atributos para o arquivo ou diretório atual.Gets or sets the attributes for the current file or directory.
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
Valor da propriedade
O FileAttributes do FileSystemInfo atual.FileAttributes of the current FileSystemInfo.
Exceções
O arquivo especificado não existe.The specified file doesn't exist. Lançada somente ao definir o valor da propriedade.Only thrown when setting the property value.
O caminho especificado é inválido.The specified path is invalid. Por exemplo, está em uma unidade não mapeada.For example, it's on an unmapped drive. Lançada somente ao definir o valor da propriedade.Only thrown when setting the property value.
O chamador não tem a permissão necessária.The caller doesn't have the required permission.
Somente .NET 5+ e .NET Core: O usuário tenta definir um valor de atributo, mas não tem uma permissão de gravação..NET 5+ and .NET Core only: The user attempts to set an attribute value but doesn't have write permission.
O caminho especificado, o nome de arquivo, ou ambos excedem o tamanho máximo definido pelo sistema.The specified path, file name, or both exceed the system-defined maximum length.
O chamador tenta definir um atributo de arquivo inválido.The caller attempts to set an invalid file attribute.
- ou --or-
Somente .NET Framework: O usuário tenta definir um valor de atributo, mas não tem uma permissão de gravação..NET Framework only: The user attempts to set an attribute value but doesn't have write permission.
Exemplos
O exemplo a seguir demonstra a Attributes propriedade.The following example demonstrates the Attributes property. Este exemplo de código faz parte de um exemplo maior fornecido para a FileSystemInfo classe.This code example is part of a larger example provided for the FileSystemInfo class.
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
Comentários
O valor da Attributes propriedade será previamente armazenado em cache se a instância atual do FileSystemInfo objeto tiver sido retornada de qualquer um dos seguintes DirectoryInfo métodos:The value of the Attributes property is pre-cached if the current instance of the FileSystemInfo object was returned from any of the following DirectoryInfo methods:
O valor pode ser armazenado em cache quando o próprio valor ou outras FileSystemInfo Propriedades forem acessadas.The value may be cached when either the value itself or other FileSystemInfo properties are accessed. Para obter o valor mais recente, chame o Refresh método.To get the latest value, call the Refresh method.
Se o caminho não existir a partir do último estado armazenado em cache, o valor de retorno será (FileAttributes)(-1) .If the path doesn't exist as of the last cached state, the return value is (FileAttributes)(-1). FileNotFoundException ou DirectoryNotFoundException só pode ser lançada ao definir o valor.FileNotFoundException or DirectoryNotFoundException can only be thrown when setting the value.
O valor dessa propriedade é uma combinação dos sinalizadores de atributo arquivo morto, compactar, diretório, oculto, offline, somente leitura, sistema e temporário.The value of this property is a combination of the archive, compressed, directory, hidden, offline, read-only, system, and temporary file attribute flags.
Quando você definir esse valor, use o operador OR de or ( | em C# ou Or Visual Basic) para aplicar mais de um valor.When you set this value, use the bitwise OR operator (| in C# or Or in Visual Basic) to apply more than one value. Para manter todos os valores existentes na Attributes propriedade, inclua o valor da Attributes propriedade em sua atribuição.To retain any existing values in the Attributes property, include the value of the Attributes property in your assignment. Por exemplo:For example:
exampleFile.Attributes = exampleFile.Attributes | FileAttributes.ReadOnly;