GetFileTime LastWrite Zeitstempel Abweichung Explorer/Anwendung



  • Hi,

    ich benutze diese Funktion, um den Zeitstempel des letzten Schreibzugriffs einer Datei zu bestimmen. Sie ist fast eine 1:1 Kopie aus der MSDN, allerdings um einige Borland spezifische Sachen erweitert:

    TDateTime get_file_time( const AnsiString& FileName )
    {
       HANDLE File = ::CreateFile( FileName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
       if( File != INVALID_HANDLE_VALUE )
       {
          FILETIME	Create = {0 }, Access = {0}, Write = {0};
          BOOL Success = ::GetFileTime( File, &Create, &Access, &Write );
          ::CloseHandle( File );
          if( Success )
          {
             SYSTEMTIME UTC, Local;
             ::FileTimeToSystemTime( &Write, &UTC );
             ::SystemTimeToTzSpecificLocalTime( NULL, &UTC, &Local );
             return TDateTime( Local.wYear, Local.wMonth, Local.wDay,
                               Local.wHour, Local.wMinute, Local.wSecond, local.wMilliseconds );
          }
       }
       throw Exception( "get_file_time() failed:\n"
    		    "Unable to determine last write time" );
    }
    

    Wenn ich die Funktion für eine Beispieldatei aufrufe bekomme ich folgende Werte:
    Windows Explorer: 28.10.2011 13:06
    UTC Time nach FileTimeToSystemTime() Aufruf: 28.10.2011 12:06
    Local Time nach SystemTimeToTzSpecificLocalTime() Aufruf: 28.10.2011 14:06

    Irgendwo läuft da was schief, die Umrechnung von UTC auf MEZ verstehe ich ja noch (+1h wegen Zeitzone, +1h wegen Winterzeit), aber warum der Explorer 13:06 anzeigt ist mir schleierhaft. Das Problem tritt auch nur für Dateien auf, deren Zeitstempel in der Sommerzeit liegt, bei Dateien in der Winterzeit ist alles ok.

    Wie bekomme ich jetzt den Zeitstempel heraus, der auch im Windows Explorer angezeigt wird?


  • Mod

    Hast Du evtl. kein NTFS sondern ein FAT Volumne.

    The NTFS file system stores time values in UTC format, so they are not affected by changes in time zone or daylight saving time. The FAT file system stores time values based on the local time of the computer. For example, a file that is saved at 3:00pm PST in Washington is seen as 6:00pm EST in New York on an NTFS volume, but it is seen as 3:00pm EST in New York on a FAT volume.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms724290(v=vs.85).aspx



  • Doch, das Volume ist NTFS.



  • Mit der Kombination GetFileTime , FileTimeToLocalFileTime , FileTimeToSystemTime funktioniert´s, obwohl in der MSDN die erste Methode empfohlen wird 😕


Anmelden zum Antworten