FileAttributes Enumeração
Definição
Fornece os atributos para arquivos e diretórios.Provides attributes for files and directories.
Esta enumeração tem um atributo FlagsAttribute que permite uma combinação bit a bit dos valores membros dela.
public enum class FileAttributes
[System.Flags]
public enum FileAttributes
[System.Flags]
[System.Serializable]
public enum FileAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum FileAttributes
[<System.Flags>]
type FileAttributes =
[<System.Flags>]
[<System.Serializable>]
type FileAttributes =
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type FileAttributes =
Public Enum FileAttributes
- Herança
- Atributos
Campos
| Archive | 32 | Esse arquivo está marcado para ser incluído na operação de backup incremental.This file is marked to be included in incremental backup operation. O Windows define esse atributo sempre que o arquivo é modificado e precisa ser limpo pelo software de backup durante o processamento do arquivo no backup incremental.Windows sets this attribute whenever the file is modified, and backup software should clear it when processing the file during incremental backup. |
| Compressed | 2048 | O arquivo está compactado.The file is compressed. |
| Device | 64 | Reservado para uso futuro.Reserved for future use. |
| Directory | 16 | O arquivo é um diretório.The file is a directory. O |
| Encrypted | 16384 | O arquivo ou diretório está criptografado.The file or directory is encrypted. Para um arquivo, isso significa que todos os dados do arquivo são criptografados.For a file, this means that all data in the file is encrypted. Para um diretório, isso significa que a criptografia é o padrão para arquivos e diretórios recém-criados.For a directory, this means that encryption is the default for newly created files and directories. |
| Hidden | 2 | O arquivo está oculto e, portanto, não está incluído em uma listagem de diretório comum.The file is hidden, and thus is not included in an ordinary directory listing. O |
| IntegrityStream | 32768 | O arquivo ou diretório inclui suporte à integridade de dados.The file or directory includes data integrity support. Quando esse valor é aplicado a um arquivo, todos os fluxos de dados do arquivo têm suporte à integridade.When this value is applied to a file, all data streams in the file have integrity support. Quando esse valor é aplicado a um diretório, todos os novos arquivos e novas subpastas do diretório, por padrão, incluem suporte à integridade.When this value is applied to a directory, all new files and subdirectories within that directory, by default, include integrity support. |
| Normal | 128 | O arquivo é um arquivo padrão que não tem nenhum atributo especial.The file is a standard file that has no special attributes. Esse atributo será válido somente se for usado sozinho.This attribute is valid only if it is used alone. O |
| NoScrubData | 131072 | O arquivo ou diretório é excluído do exame de integridade de dados.The file or directory is excluded from the data integrity scan. Quando esse valor é aplicado a uma pasta, por padrão, todos os novos arquivos e subdiretórios do diretório são excluídos da integridade de dados.When this value is applied to a directory, by default, all new files and subdirectories within that directory are excluded from data integrity. |
| NotContentIndexed | 8192 | O arquivo não será indexado pelo serviço de indexação de conteúdo do sistema operacional.The file will not be indexed by the operating system's content indexing service. |
| Offline | 4096 | O arquivo está offline.The file is offline. Os dados do arquivo não estão disponíveis imediatamente.The data of the file is not immediately available. |
| ReadOnly | 1 | Ele é somente leitura.The file is read-only. O |
| ReparsePoint | 1024 | O arquivo contém um ponto de nova análise, que é um bloco de dados definidos pelo usuário associado a um arquivo ou diretório.The file contains a reparse point, which is a block of user-defined data associated with a file or a directory. O |
| SparseFile | 512 | O arquivo é um arquivo esparso.The file is a sparse file. Em geral, arquivos esparsos são arquivos grandes cujos dados consistem principalmente em zeros.Sparse files are typically large files whose data consists of mostly zeros. |
| System | 4 | O arquivo é um arquivo do sistema.The file is a system file. Ou seja, o arquivo faz parte do sistema operacional ou é usado exclusivamente pelo sistema operacional.That is, the file is part of the operating system or is used exclusively by the operating system. |
| Temporary | 256 | O arquivo é temporário.The file is temporary. Um arquivo temporário contém dados necessários durante a execução de um aplicativo, mas que não são necessários após a conclusão do aplicativo.A temporary file contains data that is needed while an application is executing but is not needed after the application is finished. Os sistemas de arquivos tentam manter todos os dados na memória para acesso mais rápido em vez de liberar os dados de volta para o armazenamento em massa.File systems try to keep all the data in memory for quicker access rather than flushing the data back to mass storage. Um arquivo temporário deve ser excluído pelo aplicativo assim que ele não seja mais necessário.A temporary file should be deleted by the application as soon as it is no longer needed. |
Exemplos
O exemplo a seguir mostra como recuperar os atributos de um arquivo e verificar se o arquivo é somente leitura.The following example shows how to retrieve the attributes for a file and check if the file is read-only.
using System;
using System.IO;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
FileAttributes attributes = File.GetAttributes("c:/Temp/testfile.txt");
if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
Console.WriteLine("read-only file");
}
else
{
Console.WriteLine("not read-only file");
}
}
}
}
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
Dim attributes = File.GetAttributes("c:/Temp/testfile.txt")
If ((attributes And FileAttributes.ReadOnly) = FileAttributes.ReadOnly) Then
Console.WriteLine("read-only file")
Else
Console.WriteLine("not read-only file")
End If
End Sub
End Module
Comentários
Você pode obter atributos para arquivos e diretórios chamando o File.GetAttributes método e pode defini-los chamando o File.SetAttributes método.You can get attributes for files and directories by calling the File.GetAttributes method, and you can set them by calling the File.SetAttributes method.
Não é possível alterar o status de compactação de um File objeto usando o File.SetAttributes método.It is not possible to change the compression status of a File object by using the File.SetAttributes method. Em vez disso, você deve realmente compactar o arquivo usando uma ferramenta de compactação ou uma das classes no System.IO.Compression namespace.Instead, you must actually compress the file using either a compression tool or one of the classes in the System.IO.Compression namespace.
Os seguintes atributos não têm suporte no .NET Core no Linux e no macOS:The following attributes are not supported by .NET Core on Linux and macOS:
- FileAttributes.Archive
- FileAttributes.Compressed
- FileAttributes.Device
- FileAttributes.Encrypted
- FileAttributes.IntegrityStream
- FileAttributes.NoScrubData
- FileAttributes.NotContentIndexed
- FileAttributes.Offline
- FileAttributes.SparseFile
- FileAttributes.System
- FileAttributes.Temporary
Em sistemas UNIX, o valor retornado por File.GetAttributes inclui Hidden um arquivo cujo nome começa com um ponto final (".").On Unix systems, the value returned by File.GetAttributes includes Hidden for a file whose name begins with a period ("."). No macOS, você pode obter ou definir o sinalizador oculto.On macOS, you can get or set the hidden flag.