使用Windows API
BOOL GetFileInformationByHandle(
HANDLE hFile, // handle of file
LPBY_HANDLE_FILE_INFORMATION lpFileInformation // address of structure
);
typedef struct _BY_HANDLE_FILE_INFORMATION { // bhfi
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD dwVolumeSerialNumber;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD nNumberOfLinks;
DWORD nFileIndexHigh;
DWORD nFileIndexLow;
} BY_HANDLE_FILE_INFORMATION;
如果是Windows NT,还可以使用
BOOL GetFileAttributesEx(
LPCTSTR lpFileName, // pointer to string that specifies a file or directory
GET_FILEEX_INFO_LEVELS fInfoLevelId, // value that specifies the type of attribute information to obtain
LPVOID lpFileInformation // pointer to buffer to receive attribute information
);
typedef struct _WIN32_FILE_ATTRIBUTE_DATA{
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
} WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;