#include <windows.h> #include <tchar.h> #include <strsafe.h>
BOOL GetLastWriteTime(HANDLE hFile, LPTSTR lpszString, DWORD dwSize) { FILETIME ftCreate, ftAccess, ftWrite; SYSTEMTIME stUTC, stLocal; DWORD dwRet;
if(!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite)) return FALSE;
FileTimeToSystemTime(&ftWrite, &stUTC); SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal); dwRet = StringCchPrintf(lpszString, dwSize, TEXT("%02d/%02d/%d %02d:%02d"), stLocal.wMonth, stLocal.wDay, stLocal.wYear, stLocal.wHour, stLocal.wMinute);
if(S_OK == dwRet) return TRUE; else return FALSE; }
int _tmain(int argc, TCHAR **argv) { HANDLE hFile; TCHAR szBuf[MAX_PATH];
if(argc != 2) { printf("This sample takes a file name as a parameter.\n"); return 0; } hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(hFile == INVALID_HANDLE_VALUE) { printf("CreateFile failed with %d\n", GetLastError()); return 0; } if(GetLastWriteTime(hFile, szBuf, MAX_PATH)) _tprintf(TEXT("Last write time is: %s\n"), szBuf); CloseHandle(hFile); }
|