AW: Aufnahmedatum vieler jpg's ändern
14.08.2011 14:46:44
Reinhard
Hallo Boris,
kopiere dir sicherheitshalber alle jpgs in einen anderen Ordner.
Passe im Code dann den "Pfad" an auf den Ordner wo der Code wirken soll.
(Getestet mit XL 2000)
Gruß
Reinhard
In eine Standardmodul, Modul1 o.ä.:
Option Explicit
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
Sub Liste()
Dim Zei As Long, Datei As String
Dim tCreation As Date, tLastAccess As Date, tLastWrite As Date
Const Pfad As String = "c:\test\jpg\"
With Worksheets("Tabelle1")
.Columns(1).ClearContents
Datei = Dir(Pfad & "*.jpg")
Do While Datei ""
Zei = Zei + 1
Cells(Zei, 1).Value = Datei
Datei = Dir
Loop
If Zei = 0 Then Exit Sub
.Range("A1:A" & Zei).Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
For Zei = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
' Erstellungsdatum ändern
tCreation = CDate(36525 + Zei) ' 36526 = 1.1.2000
' Datum "Letzter Zugriff" ändern
tLastAccess = CDate(36525 + Zei)
' Datum "Letzter Änderung" ändern
tLastWrite = CDate(36525 + Zei)
' Zeitangaben setzen
WriteFileTime Pfad & .Cells(Zei, 1).Value, tCreation, tLastAccess, tLastWrite
Next Zei
End With
End Sub
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