GetFileAttributesEx function
Applies to: desktop apps | Metro style apps
Retrieves attributes for a specified file or directory.
To perform this operation as a transacted operation, use the GetFileAttributesTransacted function.
Syntax
BOOL WINAPI GetFileAttributesEx( __in LPCTSTR lpFileName, __in GET_FILEEX_INFO_LEVELS fInfoLevelId, __out LPVOID lpFileInformation );
Parameters
- lpFileName [in]
-
The name of the file or directory.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.
- fInfoLevelId [in]
-
A class of attribute information to retrieve.
This parameter can be the following value from the GET_FILEEX_INFO_LEVELS enumeration.
Value Meaning - GetFileExInfoStandard
The lpFileInformation parameter is a WIN32_FILE_ATTRIBUTE_DATA structure.
- lpFileInformation [out]
-
A pointer to a buffer that receives the attribute information.
The type of attribute information that is stored into this buffer is determined by the value of fInfoLevelId.
Return value
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero (0). To get extended error information, call GetLastError.
Remarks
The GetFileAttributes function retrieves file system attribute information. GetFileAttributesEx can obtain other sets of file or directory attribute information. Currently, GetFileAttributesEx retrieves a set of standard attributes that is a superset of the file system attribute information.
When the GetFileAttributesEx function is called on a directory that is a mounted folder, it returns the attributes of the directory, not those of the root directory in the volume that the mounted folder associates with the directory. To obtain the attributes of the associated volume, call GetVolumeNameForVolumeMountPoint to obtain the name of the associated volume. Then use the resulting name in a call to GetFileAttributesEx. The results are the attributes of the root directory on the associated volume.
Symbolic link behavior—If the path points to a symbolic link, the function returns attributes for the symbolic link.
Transacted Operations
If a file is open for modification in a transaction, no other thread can open the file for modification until the transaction is committed. So if a transacted thread opens the file first, any subsequent threads that try modifying the file before the transaction is committed receives a sharing violation. If a non-transacted thread modifies the file before the transacted thread does, and the file is still open when the transaction attempts to open it, the transaction receives the error ERROR_TRANSACTIONAL_CONFLICT.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | GetFileAttributesExW (Unicode) and GetFileAttributesExA (ANSI) |
See also
- File Attribute Constants
- File Management Functions
- GetFileAttributes
- GetFileAttributesTransacted
- SetFileAttributes
- Symbolic Links
Send comments about this topic to Microsoft
Build date: 4/17/2012
- 11/8/2011
- Andy Donaghey
- 9/29/2011
- Vlad Roytman
Be careful not to use the size values at all for directories. In particular, you cannot rely on them being zero (even if you wipe the struct before the call).
The reported sizes are usually zero for directories but not always.
It may seem obvious to ignore directory sizes but I ran into this where my code was acting as a callback for a 3rd party library. That library did (for some reason) request the directory sizes and went horribly wrong if anything other than zero was returned. Things were fine until I ran into a directory which (for some reason) had its size reported as 0x1000 instead of the usual zero.
(Sorry if this appears multiple times. The server keeps returning an error when I submit.)
- 11/11/2010
- LeoDavidson
- 4/7/2010
- EclecticMonk
As an alternative to using this unmanaged API, consider using the System.IO.FileSystemInfo's GetAttributes. See http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.attributes.aspx for more details on this property.
- 5/18/2009
- Thomas Lee
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern bool GetFileAttributesEx(string name, int fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);