How to reinitialize the selected file inside same loop

I am updating the date taken of files and would like to output to log the original Date taken before updating and the updated version. But after running the SetAttr command to change the date, I try pulling Date Taken again which only gives me results of Original Date Taken not new.

Ex:
imgTaken = file.metadata.image.datetaken
clickData.func.command.RunCommand "SetAttr META datetaken:+0:00:10"
imgTakenNew = file.metadata.image.datetaken

imgTaken and imgTaken New always give same results even though the date has changed. I also tried adding the ClearFiles and AddFiles command before checking for updated date thinking that it will refresh the file info but that did not work.

Here is the full Script:

[code]Option Explicit
Function OnClick(ByRef clickData)

Dim file, files, countFiles, countUpdate ,countSkip, countReview, liveStatus, dateShift
Set files = clickData.func.sourcetab.selected_files 
countFiles = 0
countUpdate = 0
countSkip = 0 
countReview = 0
liveStatus = Empty
dateShift = "+0:00:10"

If (InStr(clickData.func.qualifiers, "shift") > 0) Then
	liveStatus = " - SHIFT held during operation: All Changes are LIVE"
End If

DOpus.OutputString "Number; File Name; Date Taken; Date Taken New ;Date Digitized; Date Digitized New; Status; Reason"

For Each file in files
	Dim fileName, fileType, modifiedDate, imgTaken, imgDigitized, imgTakenNew, imgDigitizedNew
	countFiles = countFiles + 1
	fileName = file.name
	fileType = file.metadata
	imgTaken = Empty
	imgDigitized = Empty
	imgTakenNew = Empty
	imgDigitizedNew = Empty

	
	If (file.metadata = "image") Then
		imgTaken = file.metadata.image.datetaken
		imgDigitized = file.metadata.image.datedigitized
		If (imgTaken <> Empty AND imgDigitized <> Empty) Then	
			countUpdate = countUpdate + 1
			If (InStr(clickData.func.qualifiers, "shift") > 0) Then
				clickData.func.command.ClearFiles
				clickData.func.command.AddFile file
				clickData.func.command.RunCommand "SetAttr META " & """datetaken:" & dateShift & """" & " " & """datedigitized:" & dateShift & """" & " " & """lastmodifieddate:" & dateShift & """"
			End If
				clickData.func.command.ClearFiles
				clickData.func.command.AddFile file
				imgTakenNew = file.metadata.image.datetaken
				imgDigitizedNew = file.metadata.image.datedigitized
				DOpus.OutputString countFiles & "; " & fileName & "; " & imgTaken & "; " & imgTakenNew & "; " & imgDigitized & "; " & imgDigitizedNew & "; Update; 1"
		Else
			'Image does not contain Date Taken and/or Date Digitized
			DOpus.OutputString countFiles & "; " & fileName & "; " & imgTaken & "; " & imgTakenNew & "; " & imgDigitized & "; " & imgDigitizedNew & "; Review; 2"
			countReview = countReview + 1			
		End If
	Else
			'Not an image - Skip
			DOpus.OutputString countFiles & "; " & fileName & "; " & imgTaken & "; " & imgTakenNew & "; " & imgDigitized & "; " & imgDigitizedNew & "; Skip; 3"
			countSkip = countSkip + 1	
	End If
	
Next
DOpus.OutputString "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
DOpus.OutputString "Total Files: (" & countFiles & ") - Update: (" & countUpdate & "), Skip: (" & countSkip & "), Need Review: (" & countReview & ")" & liveStatus

End Function[/code]

I think you'll have to use the tab.Update method to get the new values.

btw.: You don't need the InStr function to test if a qualifier was pressed. You can simply use If clickData.func.qualifiers = "shift" Then.
I wonder why DOpus.OutputString is working. In the documentation it's just DOpus.Output

OutputString is the old name, which still works to avoid breaking a few scripts that used it already.

Im completely clueless how to use the tab.Update. I tried the following "clickData.func.sourcetab.Update" and this atleast di not give any error but it also did not change anything.

clickData.func.sourcetab.Update DOpus.Output countFiles & "; " & fileName & "; " & imgTaken & "; " & imgTakenNew & "; " & imgDigitized & "; " & imgDigitizedNew & "; Update; 1" imgTakenNew = file.metadata.image.datetaken imgDigitizedNew = file.metadata.image.datedigitized DOpus.Output countFiles & "; " & fileName & "; " & imgTaken & "; " & imgTakenNew & "; " & imgDigitized & "; " & imgDigitizedNew & "; Update; 1"

Thanks for the tips on qualifiers and DOpus.Output. I actually was wondering a lot about "DOpus.Output" vs "DOpus.OutputString" but did not mention anything since they worked the same way so far. Good to know I can now update to the short version.

The Item object caches its data once it's been created. In the next update we'll add an Item.Update method which you'll be able to call to get it to update itself. In the meantime, you can get a new Item object using the FSUtil helper.

May I suggest .Refresh instead of .Update? Update sounds like it's going to apply changes to the file system.

I think I'll wait for the Item.Update to test that out since I'm not familiar the FSUtil helper. I did however used a different method to do what I wanted. It seems a bit sloppy though since I had to redefine each of the tags four times but it's working. Since I also added a little tag update to note of time shift, I may also add a Tags check to it later to test if it hasn't been shifted already before making changes again.

[code]Option Explicit
Function OnClick(ByRef clickData)

Dim file, files, countFiles, countUpdate ,countSkip, countReview, liveStatus, timeInterval, timeShift, timeShiftTag
Set files = clickData.func.sourcetab.selected_files 
countFiles = 0
countUpdate = 0
countSkip = 0 
countReview = 0
liveStatus = Empty

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
timeInterval = "s" ' "yyyy" - Year | "q" - Quarter | "m" - Month | "y" - Day of year | "d" - Day | "w" - Weekday | "ww" - Week of year | "h" - Hour | "n" - Minute | "s" - Second
timeShift = "+3600" '3600 - 1 Hour | 630720000 - '20 Years
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
timeShiftTag = "Time Shifted: " & timeShift & timeInterval
If clickData.func.qualifiers = "shift" Then
liveStatus = " - SHIFT held during operation: All Changes are LIVE"
End If

DOpus.Output "Number; File Name; Date Taken; Date Taken New ;Date Digitized; Date Digitized New; Status; Reason"

For Each file in files
	Dim fileName, fileType, modifiedDate, modifiedDateF, modifiedDateNew, imgTaken, imgTakenF, imgTakenNew, imgDigitized, imgDigitizedF, imgDigitizedNew
	countFiles = countFiles + 1
	fileName = file.name
	imgTaken = Empty
	imgTakenF = Empty
	imgTakenNew = Empty
	imgDigitized = Empty
	imgDigitizedF = Empty
	imgDigitizedNew = Empty
	
	modifiedDate = file.modify
	modifiedDateF = file.modify.Format("D#yyyyMMdd T#HH:mm:ss")
	modifiedDateNew = DateAdd(timeInterval,timeShift,modifiedDate)	
	modifiedDateNew = DOpus.Create.Date(modifiedDateNew).Format("D#yyyyMMdd T#HH:mm:ss")

	DOpus.Output timeInterval
	If (file.metadata = "image") Then
		imgTaken = file.metadata.image.datetaken
		imgDigitized = file.metadata.image.datedigitized
		
		If (imgTaken <> Empty AND imgDigitized <> Empty) Then	
			imgTakenF = file.metadata.image.datetaken.Format("D#yyyyMMdd T#HH:mm:ss")
			imgTakenNew = DateAdd(timeInterval,timeShift,imgTaken)
			imgTakenNew = DOpus.Create.Date(imgTakenNew).Format("D#yyyyMMdd T#HH:mm:ss")

			imgDigitizedF = file.metadata.image.datedigitized.Format("D#yyyyMMdd T#HH:mm:ss")
			imgDigitizedNew = DateAdd(timeInterval,timeShift,imgDigitized)
			imgDigitizedNew = DOpus.Create.Date(imgDigitizedNew).Format("D#yyyyMMdd T#HH:mm:ss")

			countUpdate = countUpdate + 1
			'File Contains Date Taken and Date Digitized - Update with Time Shift specified and add tag to meta data
			DOpus.Output countFiles & "; " & fileName & "; " & modifiedDateF & "; " & modifiedDateNew & "; " & imgTakenF & "; " & imgTakenNew & "; " & imgDigitizedF & "; " & imgDigitizedNew & "; Update; 1"
			If clickData.func.qualifiers = "shift" Then
				clickData.func.command.ClearFiles
				clickData.func.command.AddFile file
				clickData.func.command.RunCommand "SetAttr META " & """datetaken:" & imgTakenNew & """" & " " & """datedigitized:" & imgDigitizedNew & """" & " " & """lastmodifieddate:" & modifiedDateNew & """" & " " & """tags: +" & timeShiftTag & """"
			End If
		Else
			'Image does not contain Date Taken and/or Date Digitized
			DOpus.Output countFiles & "; " & fileName & "; " & modifiedDateF & "; " & modifiedDateNew & "; " & imgTakenF & "; " & imgTakenNew & "; " & imgDigitizedF & "; " & imgDigitizedNew & "; Review; 2"
			countReview = countReview + 1			
		End If
	Else
			'Not an image - Skip
			DOpus.Output countFiles & "; " & fileName & "; " & modifiedDateF & "; " & modifiedDateNew & "; " & imgTakenF & "; " & imgTakenNew & "; " & imgDigitizedF & "; " & imgDigitizedNew & "; Skip; 3"
			countSkip = countSkip + 1	
	End If
	
Next
DOpus.Output "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
DOpus.Output "Total Files: (" & countFiles & ") - Update: (" & countUpdate & "), Skip: (" & countSkip & "), Need Review: (" & countReview & ")" & liveStatus

[/code]

There's already Lister.Update and Tab.Update so Item.Update makes more sense.

Ah cool, I hadn't come across those yet, but yeah .Update for consistency.