#include <windows.h>#include<stdio.h>//-----------Error handling Function-------------------voiderror (LPSTR lpszfunction) {CHAR szbuf[ the]; DWORD DW=GetLastError (); sprintf (Szbuf,"%s Failed:getlasterror returned%u\n", Lpszfunction, DW); MessageBox (NULL, Szbuf,"Error", MB_OK); ExitProcess (DW);}//--------------------------------------------------------BOOL getfiletime (HANDLE hfile, LPSTR lpszcreationtime, LPSTR lpszlastaccesstime, LPSTR lpszlastwritetime) {FILETIME Ftcreate, ftaccess, Ftwrite; SYSTEMTIME stUTC1, StLocal1, stUTC2, StLocal2, stUTC3, StLocal3; //--------> Get FileTime if(! Getfiletime (hfile, &ftcreate, &ftaccess, &ftwrite)) {Error ("getfiletime ()"); returnFALSE; } //---------> Conversion: FileTime-localtimeFileTimeToSystemTime (&ftcreate, &stUTC1); FileTimeToSystemTime (&ftaccess, &stUTC2); FileTimeToSystemTime (&ftwrite, &stUTC3); Systemtimetotzspecificlocaltime (NULL,&STUTC1, &stLocal1); Systemtimetotzspecificlocaltime (NULL,&STUTC2, &stLocal2); Systemtimetotzspecificlocaltime (NULL,&STUTC3, &stLocal3); //---------> Show the date and time.wsprintf (Lpszcreationtime,"creation time: \t%02d/%02d/%d%02d:%02d", Stlocal1.wday, Stlocal1.wmonth, Stlocal1.wyear, Stlocal1.whour, Stlocal1.wminute); wsprintf (Lpszlastaccesstime,"Last access time: \t%02d/%02d/%d%02d:%02d", Stlocal2.wday, Stlocal2.wmonth, Stlocal2.wyear, Stlocal2.whour, Stlocal2.wminute); wsprintf (Lpszlastwritetime,"Last modified: \t%02d/%02d/%d%02d:%02d", Stlocal3.wday, Stlocal3.wmonth, Stlocal3.wyear, Stlocal3.whour, Stlocal3.wminute); returnTRUE;}//----------------------------------------------------------------intMainintArgnChar*argv[]) { if(Argn <2) { return-1; } HANDLE hfile; TCHAR szcreationtime[ -], szlastaccesstime[ -], szlastwritetime[ -]; hfile= CreateFile (argv[1],0, File_share_read, NULL, open_existing, file_attribute_normal, NULL); Getfiletime (hfile, Szcreationtime, Szlastaccesstime, szlastwritetime); if(hfile = =Invalid_handle_value) {Error ("getlastwritetime ()"); return 0; } printf ("%s\n%s\n%s\n", Szcreationtime, Szlastaccesstime, szlastwritetime); CloseHandle (hfile); System ("Pause"); return 0;}
C + + File modification time