GOOD WORK!
Very very useful. I've just given it some extra tweak, to make it more accurate and capable of drilling into subdirectories.
' This script renames JPEG files to its actual creation time.
' using metadata found in the file
' making it possible to sort together with otherones pictures
path=Wscript.ScriptFullName
path=left(path,InStrRev(path,""))
Set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.GetFolder(path)
answer=msgbox("Renaming JPG files under the tree of " & path, vbOKCancel, "jpgRenamer")
if answer = vbOk then
nrFiles = 0
call renameInFolder(f)
MsgBox("Renamed " & nrFiles & " jpg's")
else
MsgBox "Cancelled", vbOKOnly, "jpgRenamer"
end if
sub renameInFolder (f)
for each fl in f.files
if timestampname(fl) then nrFiles = nrFiles +1
next
For Each oFSSubFolder In f.SubFolders
renameInFolder (oFSSubFolder)
Next
end sub
function timestampname (f1)
timestampname = false
ext = "." & lcase(fso.getExtensionName(f1.path))
if ext=".jpg" then
nam=fso.getFileName(f1.path)
nam=left(nam,len(nam)-len(ext))
while asc(left(nam,1)) < asc("A") or left(nam,1)="_"
nam=mid(nam,2)
wend
set file = fso.OpenTextFile(f1.path,1)
jpg=file.Read(1000)
file.close
s=""
jr = 0
for jr = 1997 to 2099
ofst = instr(jpg,jr&":")
if ofst = 0 or mid(jpg,ofst+4,1) <> ":" or mid(jpg,ofst+7,1) <> ":" or mid(jpg,ofst+10,1) <> " " or mid(jpg,ofst+13,1) <> ":" or mid(jpg,ofst+16,1) <> ":" then
ofst = 0
end if
if ofst > 0 then exit for
next
if ofst = 0 then
if instr(jpg,"PC100") then ofst = 169
if instr(jpg,"FUJIFILM") then ofst = 241
if instr(jpg,"KODAK") then ofst = 449
if instr(jpg,"CYBERSHOT") then ofst = 211
if instr(jpg,"MINOLTA") then ofst = 277
end if
if ofst = 0 then exit function
s = mid(jpg,ofst,19)
sn = ""
sn = sn & mid(s,1,4) & "-" ' year
sn = sn & mid(s,6,2) & "-" ' month
sn = sn & mid(s,9,2) & " " ' day
sn = sn & mid(s,12,2)& ":" ' hour
sn = sn & mid(s,15,2)& ":" ' minute
sn = sn & mid(s,18,2)& "" ' second
dt=0
on error resume next
dt = CDate(sn)
if dt=0 then exit function
if instr(jpg,"MINOLTA") then
dt = DateAdd("D",0,DateAdd("H",-1,DateAdd("N",-5,dt))) ' correction for this camera: adds Days, Hours and Minutes
s = year(dt) & "-" & nl(month(dt)) & "-" & nl(day(dt)) & " " & nl(Hour(dt)) & "." & nl(Minute(dt)) & "." & nl(Second(dt))
end if
if s <> "" then
sn = ""
sn = sn & mid(s,1,4) ' & "-" ' year
sn = sn & mid(s,6,2) ' & "-" ' month
sn = sn & mid(s,9,2) & "_" ' day
sn = sn & mid(s,12,2)' & "." ' hour
sn = sn & mid(s,15,2)' & "." ' minute
sn = sn & mid(s,18,2) & "_" ' second
nam = sn & nam & ".jpg"
if nam <> fso.getFileName(f1.path) then
fso.Movefile f1.path, left(f1.path,InStrRev(f1.path,"")) & nam
timestampname = true
end if
end if
end if
end function
function nl(nnn)
nl = right("00" & nnn,2)
end function
|