This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Sets the attributes for a file or directory.
To perform this operation as a transacted operation, use theSetFileAttributesTransacted function.
BOOL SetFileAttributesA( [in] LPCSTR lpFileName, [in] DWORD dwFileAttributes);
[in] lpFileName
The name of the file whose attributes are to be set.
By default, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, prepend "\\?\" to the path. For more information, seeNaming Files, Paths, and Namespaces.
Tip
Starting with Windows 10, Version 1607, you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section ofNaming Files, Paths, and Namespaces for details.
[in] dwFileAttributes
The file attributes to set for the file.
This parameter can be one or more values, combined using the bitwise-OR operator. However, all other valuesoverrideFILE_ATTRIBUTE_NORMAL.
Not all attributes are supported by this function. For more information, see the Remarks section.
The following is a list of supported attribute values.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, callGetLastError.
The following table describes how to set the attributes that cannot be set usingSetFileAttributes. For a complete list of all fileattribute values and their descriptions, seeFile Attribute Constants.
Attribute | How to Set |
---|---|
FILE_ATTRIBUTE_COMPRESSED 0x800 | To set a file's compression state, use theDeviceIoControl function with theFSCTL_SET_COMPRESSION operation. |
FILE_ATTRIBUTE_DEVICE 0x40 | Reserved; do not use. |
FILE_ATTRIBUTE_DIRECTORY 0x10 | Files cannot be converted into directories. To create a directory, use theCreateDirectory orCreateDirectoryEx function. |
FILE_ATTRIBUTE_ENCRYPTED 0x4000 | To create an encrypted file, use theCreateFile function with theFILE_ATTRIBUTE_ENCRYPTED attribute. To convert an existing file into an encrypted file, use theEncryptFile function. |
FILE_ATTRIBUTE_REPARSE_POINT 0x400 | To associate a reparse point with a file or directory, use theDeviceIoControl function with theFSCTL_SET_REPARSE_POINT operation. |
FILE_ATTRIBUTE_SPARSE_FILE 0x200 | To set a file's sparse attribute, use theDeviceIoControl function with theFSCTL_SET_SPARSE operation. |
In Windows 8 and Windows Server 2012, this function is supported by the following technologies.
Technology | Supported |
---|---|
Server Message Block (SMB) 3.0 protocol | Yes |
SMB 3.0 Transparent Failover (TFO) | Yes |
SMB 3.0 with Scale-out File Shares (SO) | Yes |
Cluster Shared Volume File System (CsvFS) | Yes |
Resilient File System (ReFS) | Yes |
For an example, seeRetrieving and Changing File Attributes.
Note
The fileapi.h header defines SetFileAttributes as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, seeConventions for Function Prototypes.
Requirement | Value |
---|---|
Minimum supported client | Windows XP [desktop apps | UWP apps] |
Minimum supported server | Windows Server 2003 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | fileapi.h (include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
Was this page helpful?
Was this page helpful?