{"id":13455,"date":"2021-12-12T08:05:34","date_gmt":"2021-12-12T08:05:34","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=13455"},"modified":"2021-12-12T08:06:22","modified_gmt":"2021-12-12T08:06:22","slug":"writing-filecreated-and-filemodified-from-vbscript","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/writing-filecreated-and-filemodified-from-vbscript\/27917.html","title":{"rendered":"Writing FileCreated And FileModified From VBScript?"},"content":{"rendered":"<p>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.<\/p>\n<p>In my script, I have tried using:<br \/>\nobjRecordSet.Fields.Item(&#8220;System.DateCreated&#8221;) = objRecordset(&#8220;System.Photo.DateTaken&#8221;)<br \/>\nThe script laughs at me, saying &#8220;800A0CB3, Current recordset does not support updating. This may be a limitation of the provider, or the selected locktype.&#8221;<\/p>\n<p>Admittedly, much of the script I&#8217;m using has been copied, and I don&#8217;t have the strongest grasp on the full capabilities of &#8220;objRecordSet.Open&#8221;, 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&#8217;t led me to a good guide on this either&#8230;)<\/p>\n<p>&#8216;=== My Script ===&#8217;<br \/>\nOption Explicit<br \/>\nDim objFSO, objConnection, objRecordSet, objFolder<br \/>\nDim OS, timeZone<br \/>\nDim FilePath, FileNameAndExtension, FileName, FileExtension<br \/>\nDim strYear, strMonth, strDay, strHour, strMinute, strSec<br \/>\nDim OldFileAndPath, NewFileAndPath, SubDirectory<br \/>\nDim SplitFileNameAndExtension, SplitFolderPath, dtmPhotoDate<\/p>\n<p>&#8216;Create the File System Object<br \/>\nSet objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet objConnection = CreateObject(&#8220;ADODB.Connection&#8221;)<br \/>\nSet objRecordSet = CreateObject(&#8220;ADODB.Recordset&#8221;)<br \/>\nFor Each OS In GetObject(&#8220;winmgmts:Win32_OperatingSystem&#8221;).Instances_<br \/>\ntimeZone = OS.CurrentTimeZone<br \/>\nNext &#8216;os<\/p>\n<p>objConnection.Open &#8220;Provider=Search.CollatorDSO;Extended Properties=&#8217;Application=Windows&#8217;;&#8221;<br \/>\nobjRecordSet.Open &#8220;SELECT System.ItemPathDisplay, System.DateCreated, System.ItemNameDisplay, System.DateModified, System.ItemFolderPathDisplay, System.Photo.DateTaken FROM SYSTEMINDEX Where System.ItemFolderPathDisplay = &#8216;C:\\Documents and Settings\\Administrator\\My Documents\\Dropbox\\DCIM\\100MEDIA'&#8221;, objConnection<\/p>\n<p>&#8216;Start at the Beginning of the RecordSet<br \/>\nobjRecordSet.MoveFirst<\/p>\n<p>Do Until objRecordSet.EOF<br \/>\nOldFileAndPath = objRecordset.Fields.Item(&#8220;System.ItemPathDisplay&#8221;)<br \/>\nFilePath = objRecordset.Fields.Item(&#8220;System.ItemFolderPathDisplay&#8221;)<br \/>\nFileNameAndExtension = objRecordset.Fields.Item(&#8220;System.ItemNameDisplay&#8221;)<br \/>\nSplitFileNameAndExtension = Split(FileNameAndExtension, &#8220;.&#8221;) &#8216;Separate file name from extension<br \/>\nIf UBound(SplitFileNameAndExtension) &gt; 0 Then &#8216;Check for extension<br \/>\nSplitFolderPath = Split(FilePath, &#8220;\\&#8221;)&#8217; Separate file path into folder list array<br \/>\nFileName = SplitFileNameAndExtension(0)<br \/>\nFileExtension = SplitFileNameAndExtension(1)<\/p>\n<p>&#8216;Extract &#8220;Date Taken&#8221; info:<br \/>\ndtmPhotoDate = DateAdd(&#8220;n&#8221;, timeZone, objRecordset(&#8220;System.Photo.DateTaken&#8221;))<br \/>\nstrDay = Day(dtmPhotoDate)<br \/>\nstrMonth = Month(dtmPhotoDate)<br \/>\nstrYear = Year(dtmPhotoDate)<br \/>\nstrHour = Hour(dtmPhotoDate)<br \/>\nstrMinute = Minute(dtmPhotoDate)<br \/>\nstrSec = Second(dtmPhotoDate)<\/p>\n<p>&#8216;Update Formatting to two characters if necessary:<br \/>\nIf Len(strDay) = 1 Then strDay = &#8220;0&#8221; &amp; strDay<br \/>\nIf Len(strMonth) = 1 Then strMonth = &#8220;0&#8221; &amp; strMonth<br \/>\nIf Len(strHour) = 1 Then strHour = &#8220;0&#8221; &amp; strHour<br \/>\nIf Len(strMinute) = 1 Then strMinute = &#8220;0&#8221; &amp; strMinute<br \/>\nIf Len(strSec) = 1 Then strSec = &#8220;0&#8221; &amp; strSec<\/p>\n<p>SubDirectory = FilePath &amp; &#8220;\\&#8221; &amp; strYear &amp; &#8220;-&#8221; &amp; strMonth &amp; &#8220;-&#8221; &amp; strDay<br \/>\nNewFileAndPath = SubDirectory &amp; &#8220;\\&#8221; &amp; strHour &amp; &#8220;h&#8221; &amp; strMinute &amp; &#8220;m&#8221; &amp; strSec &amp; &#8220;s&#8221; &amp; &#8220;.&#8221; &amp; FileExtension<\/p>\n<p>If strYear &lt;&gt; &#8220;&#8221; Then<br \/>\n&#8216;objRecordSet.Fields.Item(&#8220;System.DateCreated&#8221;) = objRecordset(&#8220;System.Photo.DateTaken&#8221;)<br \/>\n&#8216;objRecordSet.Fields.Item(&#8220;System.DateModified&#8221;) = objRecordset(&#8220;System.Photo.DateTaken&#8221;)<br \/>\nIf objFSO.FolderExists(SubDirectory) Then<br \/>\nSet objFolder = objFSO.GetFolder(SubDirectory)<br \/>\nElse<br \/>\nSet objFolder = objFSO.CreateFolder(SubDirectory)<br \/>\nEnd If<br \/>\n&#8216;WScript.Echo &#8220;Copy from &#8221; &amp; OldFileAndPath &amp; &#8221; to &#8221; &amp; NewFileAndPath<br \/>\nobjFSO.MoveFile OldFileAndPath, NewFileAndPath<br \/>\nEnd If<br \/>\nEnd If<br \/>\n&#8216;Next file in the RecordSet:<br \/>\nobjRecordset.MoveNext<br \/>\nLoop<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":3},"question-category":[55],"question_tags":[],"class_list":["post-13455","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/13455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=13455"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=13455"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=13455"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=13455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}