MSDN Library


Windows Mobile 6.5
A version of this page is also available for

This function sets the attributes of a file. A RAPI version of this function exists called CeSetFileAttributes (RAPI).

BOOL SetFileAttributes(
  LPCTSTR lpFileName, 
  DWORD dwFileAttributes


[in] Pointer to a string that specifies the name of the file whose attributes are to be set.

The default string size limit for paths is MAX_PATH characters. This limit is related to how this function parses paths.


[in] File attributes to set for the file. This parameter can be a combination of values. However, all other values override FILE_ATTRIBUTE_NORMAL. The following table shows possible values.

Value Description


Indicates that the file or directory is an archive file or directory. Applications use this attribute to mark files for backup or removal.


Indicates that the file is hidden. Hidden files and directories are not included in a typical directory listing.


Indicates that the file has no other attributes set. This attribute is valid only if used alone.


Indicates that the file is read-only. Applications can read the file, but cannot write to it or delete it. In the case of a directory, applications cannot delete it.


Indicates that the file or directory is part of, or is used exclusively by, the OS.


Indicates that the file is being used for temporary storage. File systems attempt to keep all data in memory for quicker access, rather than flushing the data back to mass storage. A temporary file should be deleted as soon as it is no longer needed.

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

This function does not work on the ROM file system. Inherently, this call is dependent on the file system support provided by a file system driver.

The FILE_ATTRIBUTE_DIRECTORY attribute cannot be set using this function. The CreateFile function and this function cannot be used to create directories. To create a directory, use the CreateDirectory function.

Not all file systems support all attributes.

Windows Embedded CEWindows CE 1.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions

© 2015 Microsoft