Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1692to1696
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Dateiattribute

Dateiattribute
20.05.2019 15:42:33
ing.grohn
Hallo Forum,
mit
Set fso = CreateObject("Scripting.FileSystemObject")
kann man die gängigen Dateiinfos abrufen.
Wenn ich aber bei einer PDF-Datei mit der rechten Mousetaste die Dateieigenschaften aufrufe, erhalte ich ein anweichendes Erstellungs- und Änderungsdatum (nämlich die "wirklichen").
Kann mir jemand zeigen, wie ich per VBA an diese Informationen komme?
Für Eure Bemühungen bedanke ich mich schon hier!
Mit freundlichen Grüßen
Albrecht

8
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Dateiattribute
20.05.2019 16:33:10
Nepumuk
Hallo Albrecht,
kann ich nicht nachvollziehen. Ist es dir möglich so eine Datei hochladen in der das Datum nicht stimmt?
Gruß
Nepumuk
AW: Dateiattribute
20.05.2019 17:05:02
ing.grohn
Hallo Nepomuk,
die Datei kann ich nicht hochladen! Sie kommt von einem Server und wird als ZIP-Archiv auf meinem Rechner abgelegt! Dabei erhält das ZIP-Archiv das Datum des downloads. Allerdings auch alle darin enthaltene Dateien haben dieses Datum?.
Hier nun ein paar Daten zu dem File:
mit
Set fsoFile = fso.GetFile("E:\Akten\_Anschreiben-AnschreibenVe.sig.pdf")
ermittelt:
Name ohne Pfad: _Anschreiben-AnschreibenVe.sig.pdf
Erstellt: 07.05.2019 11:09:56
Geändert: 07.05.2019 11:09:56
Letzter Zugriff: 20.05.2019 16:48:39
Die Daten sehe ich auch im Explorer.
Die Eigenschaften sagen: erstellt am 08.01.2019, geändert am 08.01.2019
Hilft das weiter?
MfG
Albrecht
Anzeige
AW: Dateiattribute
20.05.2019 18:14:49
Nepumuk
Hallo Albrecht,
teste mal:
Option Explicit

Private Declare PtrSafe Function CreateFileA Lib "kernel32.dll" ( _
    ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByRef lpSecurityAttributes As Long, _
    ByVal dwCreationDisposition As Long, _
    ByVal dwFlagsAndAttributes As Long, _
    ByVal hTemplateFile As LongPtr) As LongPtr
Private Declare PtrSafe Function CloseHandle Lib "kernel32.dll" ( _
    ByVal hObject As LongPtr) As Long
Private Declare PtrSafe Function GetFileTime Lib "kernel32.dll" ( _
    ByVal hFile As LongPtr, _
    ByRef lpCreationTime As FILETIME, _
    ByRef lpLastAccessTime As FILETIME, _
    ByRef lpLastWriteTime As FILETIME) As Long
Private Declare PtrSafe Function FileTimeToLocalFileTime Lib "kernel32.dll" ( _
    ByRef lpFileTime As FILETIME, _
    ByRef lpLocalFileTime As FILETIME) As Long
Private Declare PtrSafe Function FileTimeToSystemTime Lib "kernel32.dll" ( _
    ByRef lpFileTime As FILETIME, _
    ByRef lpSystemTime As SYSTEMTIME) As Long

Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Const GENERIC_WRITE As Long = &H40000000
Private Const FILE_SHARE_READ As Long = &H1
Private Const FILE_SHARE_WRITE As Long = &H2
Private Const OPEN_EXISTING As Long = 3&

Public Sub Test()
    Dim dtmCreate As Date, dtmLastAccess As Date, dtmModify As Date
    Call GetFileDateTime("G:\Eigene Dateien\Eigene PDF\pareto.pdf", dtmCreate, dtmLastAccess, dtmModify)
    MsgBox "DateCreated " & CStr(dtmCreate)
    MsgBox "LastAccess " & CStr(dtmLastAccess)
    MsgBox "LastModified " & CStr(dtmModify)
End Sub

Public Sub GetFileDateTime( _
        ByVal pvstrPath As String, _
        ByRef prdtmCreate As Date, _
        ByRef prdtmLastAccess As Date, _
        ByRef prdtmModify As Date)

    Dim lngptrHandle As LongPtr
    Dim udtDateTimeIn1 As FILETIME, udtDateTimeIn2 As FILETIME, udtDateTimeIn3 As FILETIME
    Dim udtDateTimeOut1 As FILETIME, udtDateTimeOut2 As FILETIME, udtDateTimeOut3 As FILETIME
    Dim udtSysDateTime1 As SYSTEMTIME, udtSysDateTime2 As SYSTEMTIME, udtSysDateTime3 As SYSTEMTIME
    lngptrHandle = CreateFileA(pvstrPath, GENERIC_WRITE, _
        FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0&, 0)
    Call GetFileTime(lngptrHandle, udtDateTimeIn1, udtDateTimeIn2, udtDateTimeIn3)
    Call CloseHandle(lngptrHandle)
    Call FileTimeToLocalFileTime(udtDateTimeIn1, udtDateTimeOut1)
    Call FileTimeToLocalFileTime(udtDateTimeIn2, udtDateTimeOut2)
    Call FileTimeToLocalFileTime(udtDateTimeIn3, udtDateTimeOut3)
    Call FileTimeToSystemTime(udtDateTimeOut1, udtSysDateTime1)
    Call FileTimeToSystemTime(udtDateTimeOut2, udtSysDateTime2)
    Call FileTimeToSystemTime(udtDateTimeOut3, udtSysDateTime3)
    With udtSysDateTime1
        prdtmCreate = DateSerial(.wYear, .wMonth, .wDay) + _
            TimeSerial(.wHour, .wMinute, .wSecond)
    End With
    With udtSysDateTime2
        prdtmLastAccess = DateSerial(.wYear, .wMonth, .wDay) + _
            TimeSerial(.wHour, .wMinute, .wSecond)
    End With
    With udtSysDateTime3
        prdtmModify = DateSerial(.wYear, .wMonth, .wDay) + _
            TimeSerial(.wHour, .wMinute, .wSecond)
    End With
End Sub

Gruß
Nepumuk
Anzeige
AW: Dateiattribute
20.05.2019 18:32:41
ing.grohn
Hallo Nemomuk,
vielen Dank für die Hilfe!
Das Ergebnis bring leiderauch nur die Daten die ich mit fso.getfile ermittle!
ich hab noch mal ein Bild hochgeladen
MfG
Albrecht
AW: Dateiattribute
20.05.2019 19:15:54
Nepumuk
Hallo Albrecht,
letzter Versuch. Ich komme damit aber nicht an die Sekunden ran.
Option Explicit

Public Sub Test()
    Dim dtmCreate As Date, dtmLastAccess As Date, dtmModify As Date
    Call GetFileDateTime("G:\Eigene Dateien\Eigene PDF\pareto.pdf", dtmCreate, dtmLastAccess, dtmModify)
    MsgBox "DateCreated " & CStr(dtmCreate)
    MsgBox "LastAccess " & CStr(dtmLastAccess)
    MsgBox "LastModified " & CStr(dtmModify)
End Sub

Public Sub GetFileDateTime( _
        ByVal pvstrPath As String, _
        ByRef prdtmCreate As Date, _
        ByRef prdtmLastAccess As Date, _
        ByRef prdtmModify As Date)

    
    Const FILE_PROPERTY1 As String = "Erstelldatum"
    Const FILE_PROPERTY2 As String = "Letzter Zugriff"
    Const FILE_PROPERTY3 As String = "Änderungsdatum"
    Const MAX_PROPERTYS = 255
    
    Dim objShell As Object, objFolder As Object
    Dim strFolder As String, strFile As String
    Dim lngPosition1 As Long, lngPosition2 As Long, lngPosition3 As Long
    Dim lngIndex As Long
    
    strFolder = Left$(pvstrPath, InStrRev(pvstrPath, "\") - 1)
    strFile = Mid$(pvstrPath, InStrRev(pvstrPath, "\") + 1)
    
    Set objShell = CreateObject(Class:="Shell.Application")
    Set objFolder = objShell.Namespace((strFolder))
    
    For lngIndex = 0 To MAX_PROPERTYS
        If Trim$(objFolder.GetDetailsOf(vbNullString, lngIndex)) <> vbNullString Then
            If InStr(FILE_PROPERTY1, objFolder.GetDetailsOf(vbNullString, lngIndex)) > 0 Then
                lngPosition1 = lngIndex
            ElseIf InStr(FILE_PROPERTY2, objFolder.GetDetailsOf(vbNullString, lngIndex)) > 0 Then
                lngPosition2 = lngIndex
            ElseIf InStr(FILE_PROPERTY3, objFolder.GetDetailsOf(vbNullString, lngIndex)) > 0 Then
                lngPosition3 = lngIndex
            End If
        End If
    Next
    
    prdtmCreate = CDate(objFolder.GetDetailsOf(objFolder.ParseName(strFile), lngPosition1))
    prdtmLastAccess = CDate(objFolder.GetDetailsOf(objFolder.ParseName(strFile), lngPosition2))
    prdtmModify = CDate(objFolder.GetDetailsOf(objFolder.ParseName(strFile), lngPosition3))
    
    Set objShell = Nothing
    Set objFolder = Nothing
    
End Sub

Gruß
Nepumuk
Anzeige
AW: Dateiattribute
20.05.2019 19:37:07
ing.grohn
Hallo Nepumuk,
die Sekunden sind egal, ich hätte gern gewusst, wann denn die Datei nun erstellt wurde.
auch die neue Version bring nur die alten Daten!
Trotzdem bedankt für deine Hilfe
MfG
Albrecht
AW: Dateiattribute
20.05.2019 19:16:10
ing.grohn
Hallo Nemomuk,
vielen Dank für die Hilfe!
Das Ergebnis bring leiderauch nur die Daten die ich mit fso.getfile ermittle!
ich hab noch mal ein Bild hochgeladen
MfG
Albrecht
AW: Dateiattribute
20.05.2019 18:25:27
ing.grohn
Hier noch mal ein Bildschirmausschnitt:
Userbild
mfg
Albrecht

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige