- Offizieller Beitrag
Ich benötige für Synchronisationsvorgänge die Datei-Time Werte mit Milisekunden und verwende deshalb _Date_Time_GetFileTime zur Abfrage.
Laut Funktionsbeschreibung gibt es zwar Probleme in der Verfügbarkeit der Infos abhängig vom Dateisystem. Aber grundsätzlich sollten zumindest die Dateiinformationen identisch abfragbar sein:
[0] - $tagFILETIME structure with the date and time the file was created
[1] - $tagFILETIME structure with the date and time the file was accessed
[2] - $tagFILETIME structure with the date and time the file was modified
Das stimmt, wenn ich Dateien von der Festplatte (NTFS) abfrage.
Bei Abfrage von einem USB-Stick (NTFS) ist Last Access eindeutig das Create-Datum (am Ältesten).
Bei einem anderen USB-Stick (NTFS, derselbe Hersteller) ist das Create-Datum OK. Aber Modified ist frischer als Last Access? Wie kann eine Datei modifiziert sein, ohne dass darauf zugegriffen wird?
Auf einer SD-Card im NTFS stimmt die Zuordnung.
Obwohl alle Datenträger NTFS haben, bekomme ich unterschiedliche Ergebnisse. Für mich unerklärlich.
Vielleicht könnt ihr mal bei euch mit verschiedenen Datenträgern testen und mitteilen, was bei euch rauskommt.
Testskript:
#include <WinAPI.au3>
#include <Date.au3>
Local $sFile = "YourFilePath"
ConsoleWrite('Created: ' & _GetFileTime($sFile, 0, 2) & @CRLF)
ConsoleWrite('Modified: ' & _GetFileTime($sFile, 1, 2) & @CRLF)
ConsoleWrite('Last Access: ' & _GetFileTime($sFile, 2, 2) & @CRLF)
; #FUNCTION# ====================================================================================================================
; Name ..........: _GetFileTime
; Description ...: Gets the time of creation, modification or last access of an file.
; ...............: Compared to the FileGetTime function, the weekday and milliseconds can also be queried here.
; Parameters ....: $_sFile The file path.
; ...............: $_iPart What to get: 0=created, 1=modified(Default), 2=last access
; ...............: $_iString The kind of return. -1=Array [Month, Day, Year, Hour, Minutes, Seconds, Milliseconds, Day of week] (Default)
; ...............: 0=String 'mm/dd/yyyy hh:mm:ss'
; ...............: 1=String 'yyyy/mm/dd hh:mm:ss'
; ...............: 2=String 'yyyy/mm/dd hh:mm:ss.ms'
; ...............: 3=String 'day yyyy/mm/dd hh:mm:ss.ms' (day in short form)
; Return values .: Array or string with data of file time.
; Author ........: BugFix
; Remarks .......: Required: #include <WinAPI.au3>, #include <Date.au3>
; ===============================================================================================================================
Func _GetFileTime($_sFile, $_iPart=1, $_iString=-1)
Local Static $iLang = StringInStr(' 0407 0807 0C07 1007 1407 ', ' ' & String(@OSLang) & ' ') <> 0 ? 1 : 0
Local Static $aWDay[7][2] = [['Sun','So'],['Mon','Mo'],['Tue','Di'],['Wed','Mi'],['Thur','Do'],['Fri','Fr'],['Sat','Sa']]
Local $vRet, $hFile = _WinAPI_CreateFile($_sFile, 2, 2)
Local $a_tFILETIME = _Date_Time_GetFileTime($hFile) ;
_WinAPI_CloseHandle($hFile)
If $_iString = 0 Or $_iString = 1 Then
$vRet = _Date_Time_FileTimeToStr($a_tFILETIME[$_iPart], $_iString)
Else
$vRet = _Date_Time_FileTimeToArray($a_tFILETIME[$_iPart])
If $_iString = 2 Then
$vRet = StringFormat('%d/%02i/%02i %02i:%02i:%02i.%03i', $vRet[2], $vRet[0], $vRet[1], $vRet[3], $vRet[4], $vRet[5], $vRet[6])
ElseIf $_iString = 3 Then
$vRet = StringFormat('%s %d/%02i/%02i %02i:%02i:%02i.%03i', $aWDay[$vRet[7]][$iLang], $vRet[2], $vRet[0], $vRet[1], $vRet[3], $vRet[4], $vRet[5], $vRet[6])
EndIf
EndIf
Return $vRet
EndFunc ;==>_GetFileTime
Alles anzeigen