getfileattributesex (kernel32)
Last changed: Kåre Smith-83.108.28.160

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetFileAttributesEx(string lpFileName,
   GET_FILEEX_INFO_LEVELS fInfoLevelId, IntPtr lpFileInformation);

Alternative C# Signature:

[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetFileAttributesEx(string lpFileName,
  GET_FILEEX_INFO_LEVELS fInfoLevelId, out WIN32_FILE_ATTRIBUTE_DATA fileData);

User-Defined Types:

WIN32_FILE_ATTRIBUTE_DATA

GET_FILEEX_INFO_LEVELS

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

public static bool GetFileAttributesEx(string lpFileName, out WIN32_FILE_ATTRIBUTE_DATA fileData) {
    return GetFileAttributesEx(lpFileName, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard,
        out fileData);
}

WIN32 fileData;

if (GetFileAttributesEx(path, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out fileData))

{

     lastAccessTime = GetDateTimeFromFILETIME(fileData.ftLastAccessTime);
     lastModifiedTime = GetDateTimeFromFILETIME(fileData.ftLastWriteTime);

}

else

{

     throw new ApplicationException("Unable to obtain details for path " + path);

}

}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation