Windows API Reference

SetFileAttributes Function

Sets the specified attributes for a file or a directory.

Syntax


BOOL SetFileAttributes(
  [in] LPCTSTR lpFileName,
  [in] DWORD   dwFileAttributes
);
                    

Parameters

Parameter Description
lpFileName A pointer to a null-terminated string that specifies the name of the file or directory for which the attributes are to be set.
dwFileAttributes The file attributes to set for the specified file or directory. This parameter can be a combination of the following values:
  • FILE_ATTRIBUTE_ARCHIVE (0x00000020)
  • FILE_ATTRIBUTE_COMPRESSED (0x00000800)
  • FILE_ATTRIBUTE_DIRECTORY (0x00000010)
  • FILE_ATTRIBUTE_ENCRYPTED (0x00004000)
  • FILE_ATTRIBUTE_HIDDEN (0x00000002)
  • FILE_ATTRIBUTE_NORMAL (0x00000080)
  • FILE_ATTRIBUTE_OFFLINE (0x00001000)
  • FILE_ATTRIBUTE_READONLY (0x00000001)
  • FILE_ATTRIBUTE_SYSTEM (0x00000004)
  • FILE_ATTRIBUTE_TEMPORARY (0x00000100)

Return value

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The following attributes are not supported by the SetFileAttributes function:

  • FILE_ATTRIBUTE_DIRECTORY
  • FILE_ATTRIBUTE_ENCRYPTED
  • FILE_ATTRIBUTE_OFFLINE

If you attempt to set one of these attributes, the function fails and GetLastError returns ERROR_INVALID_PARAMETER.

Note: The system can map a higher file attribute, such as FILE_ATTRIBUTE_ARCHIVE, to the FILE_ATTRIBUTE_NORMAL attribute.
Important: Applications should not create files with the FILE_ATTRIBUTE_DIRECTORY attribute.

Requirements

Header: windows.h

Library: Kernel32.lib

DLL: Kernel32.dll