잠토의 잠망경

[FILE 생성 시간, 접근 시간, Write 시간] GetFileTime, FileTimeToSystemTime, SystemTimeToTzSpecificLocalTime 본문

카테고리 없음

[FILE 생성 시간, 접근 시간, Write 시간] GetFileTime, FileTimeToSystemTime, SystemTimeToTzSpecificLocalTime

잠수함토끼 2012. 1. 1. 23:38

File의 생성 시간, 접근 시간, Write 시간 알아내기

http://www.tipssoft.com/ 에서 학습한 내용을 바탕으로 재 코딩 한 것임을 알려드립니다.


voidCGetFileTimeDlg::OnBnClickedButton1() 
{ 

    // TODO: 여기에컨트롤알림처리기코드를추가합니다. 

    /* 

     

    The GetFileTime function retrieves the date and time that a file was created, last accessed, and last modified.
 
 

    BOOL GetFileTime( 

                HANDLE hFile,            // identifies the file 

                LPFILETIME lpCreationTime,        // address of creation time 

                LPFILETIME lpLastAccessTime,    // address of last access time 

                LPFILETIME lpLastWriteTime     // address of last write time 

    ); 

 

  

    The FileTimeToSystemTime function converts a 64-bit file time to system time format.
 
 

    BOOL FileTimeToSystemTime( 

                CONST FILETIME * lpFileTime,    // pointer to file time to convert
 
                LPSYSTEMTIME lpSystemTime         // pointer to structure to receive system time
 
                ); 

     

    The SystemTimeToTzSpecificLocalTime function converts a Coordinated Universal Time (UTC) to a specified time zone's corresponding local time.
 
 

    BOOL SystemTimeToTzSpecificLocalTime ( 

                        LPTIME_ZONE_INFORMATION lpTimeZoneInformation,    // pointer to time zone of interest
 
                        LPSYSTEMTIME lpUniversalTime,            // pointer to universal time of interest
 
                        LPSYSTEMTIME lpLocalTime                // pointer to structure to receive local time
 
                        ); 

    */     

    DWORD dWord = 0;

    HANDLE h_file = CreateFile(_T("C:\\test.ini"),GENERIC_READ,FILE_SHARE_READ,NULL,

                            OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); 

     

    if(h_file != INVALID_HANDLE_VALUE) 

    { 

        FILETIME create_time, access_time, write_time;

        BOOL retVal = GetFileTime(    h_file,    //    identifies the file 

                        &create_time,    //    address of creation time 

                        &access_time,    //    address of last access time 

                        &write_time);    //    address of last write time     

         

        if(!retVal) 
        { 
            dWord = GetLastError(); 
        } 
		
        SYSTEMTIME write_system_time, write_local_time;

        retVal = FileTimeToSystemTime(  &write_time,        //    pointer to file time to convert
										&write_system_time);//    pointer to structure to receive system time
										
        if(!retVal) 

        { 
			dWord = GetLastError(); 
        } 

        retVal = SystemTimeToTzSpecificLocalTime( 	NULL,                // 
													&write_system_time,    // UTC 
													&write_local_time);    // 변경될LOCAL 시간

        if(!retVal) 
        { 
            dWord = GetLastError(); 
		} 

        CloseHandle(h_file); 
    } 
    else
    { 
        DWORD dWord = GetLastError();
    } 
} 

 

Comments