SetFileAttributesW Function
Sets the specified file attributes for a file.
BOOL SetFileAttributesW(
_In_ LPCWSTR lpFileName,
_In_ DWORD dwFileAttributes
);
Syntax
#include <windows.h>
#include <fileapi.h>
BOOL SetFileAttributesW(
LPCWSTR lpFileName,
DWORD dwFileAttributes
);
Parameters
| Parameter | Type | Description |
|---|---|---|
lpFileName |
_In_ LPCWSTR |
The name of the file whose attributes are to be set. The name must be a Unicode string. |
dwFileAttributes |
_In_ DWORD |
The file attributes to set for the specified file. This parameter can be a combination of the following values.
|
Return Value
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
Remarks
You can combine attributes using the bitwise OR operator.
The FILE_ATTRIBUTE_NORMAL attribute can be used to indicate that a file is an ordinary file with no other attributes set.
Attributes that are not specified are not changed.
To remove an attribute, you must specify the attribute in the dwFileAttributes parameter and combine it with the bitwise OR operator with the existing attributes. However, some attributes cannot be unset once set, such as FILE_ATTRIBUTE_DEVICE.
FILE_ATTRIBUTE_ENCRYPTED and FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS attributes are new in Windows Vista.
FILE_ATTRIBUTE_NORMAL attribute is typically used with CreateFile to specify that a file has no special attributes. When used with SetFileAttributesW, it clears all other attributes.
Requirements
| Interface | Value |
|---|---|
| Minimum supported client | Windows XP |
| Minimum supported server | Windows Server 2003 |
| Header | fileapi.h (include windows.h) |
| Unicode and ANSI versions | SetFileAttributesW (Unicode) and SetFileAttributesA (ANSI) |