I have a folder on a Windows 2003 R2 PC, which syncs with my phone; the phone takes pictures in jpg format and places them in the folder, and an app on my phone syncs whatever is there. I have cobbled together a script which executes as a scheduled task; the script reads the date taken property and sorts/renames my photos, and from here I can move them to a NAS and back them up for safekeeping. The date created property on the PC is relative to the time the file was synchronized, and not the time the picture was taken on the phone. I would like to have my script write to the date created (and date modified, just to keep things neat) the same info as is stored in date taken.
In my script, I have tried using:
objRecordSet.Fields.Item(“System.DateCreated”) = objRecordset(“System.Photo.DateTaken”)
The script laughs at me, saying “800A0CB3, Current recordset does not support updating. This may be a limitation of the provider, or the selected locktype.”
Admittedly, much of the script I’m using has been copied, and I don’t have the strongest grasp on the full capabilities of “objRecordSet.Open”, so I assume I may need to do something different to be able to write to these properties? (So far my attempts at Googling haven’t led me to a good guide on this either…)
‘=== My Script ===’
Option Explicit
Dim objFSO, objConnection, objRecordSet, objFolder
Dim OS, timeZone
Dim FilePath, FileNameAndExtension, FileName, FileExtension
Dim strYear, strMonth, strDay, strHour, strMinute, strSec
Dim OldFileAndPath, NewFileAndPath, SubDirectory
Dim SplitFileNameAndExtension, SplitFolderPath, dtmPhotoDate
‘Create the File System Object
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objConnection = CreateObject(“ADODB.Connection”)
Set objRecordSet = CreateObject(“ADODB.Recordset”)
For Each OS In GetObject(“winmgmts:Win32_OperatingSystem”).Instances_
timeZone = OS.CurrentTimeZone
Next ‘os
objConnection.Open “Provider=Search.CollatorDSO;Extended Properties=’Application=Windows’;”
objRecordSet.Open “SELECT System.ItemPathDisplay, System.DateCreated, System.ItemNameDisplay, System.DateModified, System.ItemFolderPathDisplay, System.Photo.DateTaken FROM SYSTEMINDEX Where System.ItemFolderPathDisplay = ‘C:\Documents and Settings\Administrator\My Documents\Dropbox\DCIM\100MEDIA'”, objConnection
‘Start at the Beginning of the RecordSet
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
OldFileAndPath = objRecordset.Fields.Item(“System.ItemPathDisplay”)
FilePath = objRecordset.Fields.Item(“System.ItemFolderPathDisplay”)
FileNameAndExtension = objRecordset.Fields.Item(“System.ItemNameDisplay”)
SplitFileNameAndExtension = Split(FileNameAndExtension, “.”) ‘Separate file name from extension
If UBound(SplitFileNameAndExtension) > 0 Then ‘Check for extension
SplitFolderPath = Split(FilePath, “\”)’ Separate file path into folder list array
FileName = SplitFileNameAndExtension(0)
FileExtension = SplitFileNameAndExtension(1)
‘Extract “Date Taken” info:
dtmPhotoDate = DateAdd(“n”, timeZone, objRecordset(“System.Photo.DateTaken”))
strDay = Day(dtmPhotoDate)
strMonth = Month(dtmPhotoDate)
strYear = Year(dtmPhotoDate)
strHour = Hour(dtmPhotoDate)
strMinute = Minute(dtmPhotoDate)
strSec = Second(dtmPhotoDate)
‘Update Formatting to two characters if necessary:
If Len(strDay) = 1 Then strDay = “0” & strDay
If Len(strMonth) = 1 Then strMonth = “0” & strMonth
If Len(strHour) = 1 Then strHour = “0” & strHour
If Len(strMinute) = 1 Then strMinute = “0” & strMinute
If Len(strSec) = 1 Then strSec = “0” & strSec
SubDirectory = FilePath & “\” & strYear & “-” & strMonth & “-” & strDay
NewFileAndPath = SubDirectory & “\” & strHour & “h” & strMinute & “m” & strSec & “s” & “.” & FileExtension
If strYear <> “” Then
‘objRecordSet.Fields.Item(“System.DateCreated”) = objRecordset(“System.Photo.DateTaken”)
‘objRecordSet.Fields.Item(“System.DateModified”) = objRecordset(“System.Photo.DateTaken”)
If objFSO.FolderExists(SubDirectory) Then
Set objFolder = objFSO.GetFolder(SubDirectory)
Else
Set objFolder = objFSO.CreateFolder(SubDirectory)
End If
‘WScript.Echo “Copy from ” & OldFileAndPath & ” to ” & NewFileAndPath
objFSO.MoveFile OldFileAndPath, NewFileAndPath
End If
End If
‘Next file in the RecordSet:
objRecordset.MoveNext
Loop
How To Ask Questions The Smart Way