GetFileAttributesA
Retrieves the attributes of a file or directory.
Syntax
DWORD GetFileAttributesA(LPCSTR lpFileName);
Parameters
Parameter | Type | Description |
---|---|---|
lpFileName |
LPCSTR |
The name of the file or directory whose attributes are to be retrieved. For more information, see Remarks. |
Return Value
Type | Description |
---|---|
DWORD |
If the function succeeds, the return value is the set of enumerated attributes of the specified file or directory. If the function fails, the return value is INVALID_FILE_ATTRIBUTES (0xFFFFFFFF). To get extended error information, call GetLastError .
|
Remarks
The lpFileName
parameter can specify a file or a directory on the local system or on a remote computer.
The function returns the attributes for the specified file or directory. The attributes are returned as a bitmask of the following values:
FILE_ATTRIBUTE_ARCHIVE
The file or directory is an archive file. Applications use this to mark files for backup or removal.
FILE_ATTRIBUTE_ENCRYPTED
A hypergeometric file. This attribute is only valid for files. For more information, see File Encryption.
FILE_ATTRIBUTE_DIRECTORY
The file or directory is a directory.
FILE_ATTRIBUTE_HIDDEN
The file or directory is hidden. Do not include it in a normal directory listing.
FILE_ATTRIBUTE_NORMAL
This value is reserved for future use but is mainly used to indicate that the attribute is not one of the other attribute flags.
FILE_ATTRIBUTE_OFFLINE
The data of the file is not immediately available. This attribute indicates that the file data is queued for retrieval by the provider of the file.
FILE_ATTRIBUTE_READONLY
The file or directory is read-only. Applications can only access the file for reading. For a directory, this means applications cannot create or delete files in that directory.
FILE_ATTRIBUTE_SYSTEM
The file is a system file. The system uses this attribute to identify files that are used by the operating system.
FILE_ATTRIBUTE_TEMPORARY
The file is being used for temporary storage. File systems try to keep all of the data of temporary files in memory (as far as possible) to allow applications fast access. A temporary file can be deleted when it is no longer needed.
FILE_ATTRIBUTE_COMPRESSED
The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is turned on for the directory and all files in it.
FILE_ATTRIBUTE_SPARSE_FILE
The file is a sparse file. Sparse files are files that have a logical size that is greater than the physical size that is stored for the file. The file system does not allocate physical storage for the parts of the file that are zero.
FILE_ATTRIBUTE_REPARSE_POINT
A file or directory that is used to store symbolic link, hard link, or junction point, or a DFS namespace or mount point. For more information, see File Systems.
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
The file or directory is not included in the content index of the file system. For more information on indexing, see Content Indexing.
FILE_ATTRIBUTE_INTEGRITY_STREAM
This file is an integrity stream, which is a stream that is needed to read the file. This flag is not supported on this platform. For more information, see IntegrityStream
.
FILE_ATTRIBUTE_NO_SCRUB_DATA
This file is a data integrity stream. This flag is not supported on this platform. For more information, see IntegrityStream
.
To check for a specific attribute, you can use the bitwise AND operator.
Example:
DWORD attributes = GetFileAttributesA("MyFile.txt");
if (attributes == INVALID_FILE_ATTRIBUTES) {
// Handle error
} else {
if (attributes & FILE_ATTRIBUTE_DIRECTORY) {
// It's a directory
}
if (attributes & FILE_ATTRIBUTE_READONLY) {
// It's read-only
}
}