Anmelden | registrieren | Kategorien



 
Archiv
Ansicht:   
Suche   erweiterte Suche
Infopost Aktuelles: > [Wichtige Forumsinformationen] [NT-Karte] [NT-Fotos] [NT-Fotowettbewerb]

Nachricht aus dem Archiv

Diese Nachricht stammt aus dem Netz-Treff.de-Archiv

Backowe [Gast] schrieb am 04.July.2009, 23:16:29 in der Kategorie pc.windows

Mit VBA Dateidatum ändern

Hallo oldi,

hoffe es passt so!  :-)

\' zunächst die benötigten Deklarationen
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 Declare Function CreateFile Lib \"kernel32\" _
  Alias \"CreateFileA\" ( _
  ByVal lpFilename As String, _
  ByVal dwDesiredAccess As Long, _
  ByVal dwShareMode As Long, _
  ByVal lpSecurityAttributes As Long, _
  ByVal dwCreationDisposition As Long, _
  ByVal dwFlagsAndAttributes As Long, _
  ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib \"kernel32\" ( _
  ByVal hObject As Long) As Long
Private Declare Function GetFileTime Lib \"kernel32\" ( _
  ByVal hFile As Long, _
  lpCreationTime As FileTime, _
  lpLastAccessTime As FileTime, _
  lpLastWriteTime As FileTime) As Long
Private Declare Function SetFileTime Lib \"kernel32\" ( _
  ByVal hFile As Long, _
  lpCreationTime As FileTime, _
  lpLastAccessTime As FileTime, _
  lpLastWriteTime As FileTime) As Long
Private Declare Function FileTimeToLocalFileTime Lib \"kernel32\" ( _
  lpFileTime As FileTime, _
  lpLocalFileTime As FileTime) As Long
Private Declare Function FileTimeToSystemTime Lib \"kernel32\" ( _
  lpFileTime As FileTime, _
  lpSystemTime As SYSTEMTIME) As Long
Private Declare Function SystemTimeToFileTime Lib \"kernel32\" ( _
  lpSystemTime As SYSTEMTIME, _
  lpFileTime As FileTime) As Long
Private Declare Function LocalFileTimeToFileTime Lib \"kernel32\" ( _
  lpLocalFileTime As FileTime, _
  lpFileTime As FileTime) As Long
 
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
 
\' Die beiden nachfolgenden Routinen werden zum
\' Lesen/Schreiben der Zeitangaben benötigt

Private Function ReadFileTime(ByVal sFilename As String, _
  tCreation As Date, tLastAccess As Date, _
  tLastWrite As Date) As Boolean
  \'
  \' *** Datum/Zeitwert einer Datei ermitteln
  Dim fHandle As Long
 
  Dim ftCreation As FileTime
  Dim ftLastAccess As FileTime
  Dim ftLastWrite As FileTime
  Dim LocalFileTime As FileTime
  Dim LocalSystemTime As SYSTEMTIME
 
  ReadFileTime = False
  fHandle = CreateFile(sFilename, GENERIC_READ, 0, 0, _
    OPEN_EXISTING, 0, 0)
  If fHandle <> 0 Then
    \' Zeitinformationen auslesen
    If GetFileTime(fHandle, ftCreation, ftLastAccess, _
      ftLastWrite) <> 0 Then
 
      \' Erstellungsdatum
      FileTimeToLocalFileTime ftCreation, LocalFileTime
      FileTimeToSystemTime LocalFileTime, LocalSystemTime
      With LocalSystemTime
        tCreation = CDate(Format$(.wDay) & \".\" & _
          Format$(.wMonth) & \".\" & Format$(.wYear) & \" \" & _
          Format$(.wHour) & \":\" & Format$(.wMinute, \"00\") & _
          \":\" & Format$(.wSecond, \"00\"))
      End With
 
      \' Letzter Zugriff
      FileTimeToLocalFileTime ftLastAccess, LocalFileTime
      FileTimeToSystemTime LocalFileTime, LocalSystemTime
      With LocalSystemTime
        tLastAccess = CDate(Format$(.wDay) & \".\" & _
          Format$(.wMonth) & \".\" & Format$(.wYear) & \" \" & _
          Format$(.wHour) & \":\" & Format$(.wMinute, \"00\") & _
          \":\" & Format$(.wSecond, \"00\"))
      End With
 
      \' Letzte Änderung
      FileTimeToLocalFileTime ftLastWrite, LocalFileTime
      FileTimeToSystemTime LocalFileTime, LocalSystemTime
      With LocalSystemTime
        tLastWrite = CDate(Format$(.wDay) & \".\" & _
          Format$(.wMonth) & \".\" & Format$(.wYear) & \" \" & _
          Format$(.wHour) & \":\" & Format$(.wMinute, \"00\") & _
          \":\" & Format$(.wSecond, \"00\"))
      End With
 
      ReadFileTime = True
    End If
    CloseHandle fHandle
  End If
End Function
 
Private Function WriteFileTime(ByVal sFilename As String, _
  ByVal tCreation As Date, ByVal tLastAccess As Date, _
  ByVal tLastWrite As Date) As Boolean
  \'
  \' *** Datum/Zeitwert einer Datei setzen
  Dim fHandle As Long
 
  Dim ftCreation As FileTime
  Dim ftLastAccess As FileTime
  Dim ftLastWrite As FileTime
  Dim LocalFileTime As FileTime
  Dim LocalSystemTime As SYSTEMTIME
 
  WriteFileTime = False
  fHandle = CreateFile(sFilename, GENERIC_WRITE, 0, _
    0, OPEN_EXISTING, 0, 0)
  If fHandle <> 0 Then
    \' Erstellungsdatum
    With LocalSystemTime
      .wDay = Day(tCreation)
      .wDayOfWeek = Weekday(tCreation)
      .wMonth = Month(tCreation)
      .wYear = Year(tCreation)
      .wHour = Hour(tCreation)
      .wMinute = Minute(tCreation)
      .wSecond = Second(tCreation)
    End With
    SystemTimeToFileTime LocalSystemTime, LocalFileTime
    LocalFileTimeToFileTime LocalFileTime, ftCreation
 
    \' Letzter Zugriff
    With LocalSystemTime
      .wDay = Day(tLastAccess)
      .wDayOfWeek = Weekday(tLastAccess)
      .wMonth = Month(tLastAccess)
      .wYear = Year(tLastAccess)
      .wHour = Hour(tLastAccess)
      .wMinute = Minute(tLastAccess)
      .wSecond = Second(tLastAccess)
    End With
    SystemTimeToFileTime LocalSystemTime, LocalFileTime
    LocalFileTimeToFileTime LocalFileTime, ftLastAccess
 
    \' Letzte Änderung
    With LocalSystemTime
      .wDay = Day(tLastWrite)
      .wDayOfWeek = Weekday(tLastWrite)
      .wMonth = Month(tLastWrite)
      .wYear = Year(tLastWrite)
      .wHour = Hour(tLastWrite)
      .wMinute = Minute(tLastWrite)
      .wSecond = Second(tLastWrite)
    End With
    SystemTimeToFileTime LocalSystemTime, LocalFileTime
    LocalFileTimeToFileTime LocalFileTime, ftLastWrite
 
    If SetFileTime(fHandle, ftCreation, ftLastAccess, _
      ftLastWrite) <> 0 Then
      WriteFileTime = True
    End If
    CloseHandle fHandle
  End If
End Function

Sub DateiAendern()
Dim tCreation As Date \' Erstellt am
Dim tLastAccess As Date \' Letzter Zugriff
Dim tLastWrite As Date  \' Letzte Änderung
Dim Datei As String
Datei = \"j:\\01.jpg\"
 
\' Zeitangaben lesen
If ReadFileTime(Datei, tCreation, tLastAccess, tLastWrite) Then
  \' Erstellungsdatum ändern
  tCreation = CDate(\"01.11.2000 17:35:41\")
 
  \' Datum \"Letzter Zugriff\" ändern
  tLastAccess = CDate(\"01.11.2000 17:35:41\")
 
  \' Datum \"Letzter Änderung\" ändern
  tLastWrite = CDate(\"01.11.2000 17:35:41\")
 
  \' Zeitangaben setzen
  WriteFileTime Datei, tCreation, tLastAccess, tLastWrite
End If
End Sub

Archiv
Ansicht:   
Suche   erweiterte Suche

weitere Informationen
Netz-Treff | Kontakt | Impressum | Nutzungsbedingungen | Datenschutz
30454 Beiträge in 2474 Threads (Archiv: 498114 Beiträge in 42568 Threads), 1738 registrierte Benutzer, 29 User online (4 User, 25 Gäste)
based on a 2004 version of my little forum  RSS-Feed  ^