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.
  • FILE_ATTRIBUTE_ARCHIVE (0x00000020)
  • FILE_ATTRIBUTE_COMPRESSED (0x00000800)
  • FILE_ATTRIBUTE_DEVICE (0x00000040)
  • FILE_ATTRIBUTE_DIRECTORY (0x00000010)
  • FILE_ATTRIBUTE_ENCRYPTED (0x00004000)
  • FILE_ATTRIBUTE_HIDDEN (0x00000002)
  • FILE_ATTRIBUTE_INTEGRITY_STREAM (0x00008000)
  • FILE_ATTRIBUTE_NORMAL (0x00000080)
  • FILE_ATTRIBUTE_NO_COMPRESSION (0x00002000)
  • FILE_ATTRIBUTE_OFFLINE (0x00001000)
  • FILE_ATTRIBUTE_READONLY (0x00000001)
  • FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS (0x00004000)
  • FILE_ATTRIBUTE_RECALL_ON_OPEN (0x00000001)
  • FILE_ATTRIBUTE_SPARSE_FILE (0x00000200)
  • FILE_ATTRIBUTE_SYSTEM (0x00000004)
  • FILE_ATTRIBUTE_TEMPORARY (0x00000100)
  • FILE_ATTRIBUTE_TRANSACTED_METADATA (0x00020000)

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.

Note: The FILE_ATTRIBUTE_ENCRYPTED and FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS attributes are new in Windows Vista.
Important: The 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)

See Also