Copy a variable date into Date Taken and Modified Date

The date string has to be formatted a particular way; see the documentation for the createdate keyword under Keywords for SetAttr META for examples.

Thanks jon, this is super helpful.

It almost works now but there is still an issue with the date. After I convert it to the correct format (D#yyyyMMdd T#HH:mm:ss"), It's now only copying over the date, not the time. See here: goo.gl/zs4OSa

This is the updated code:

Option Explicit
Function OnClick(ByRef clickData)

	Dim file, files
	Set files = clickData.func.sourcetab.selected_files 
	For Each file in files
		Dim fileName, modifiedDate, modifiedDateF1
		fileName = file.name
DOpus.OutputString fileName & " - File Name"
		modifiedDate = file.modify
DOpus.OutputString modifiedDate & " - ModDate"
		modifiedDateF1 = file.modify.Format("D#yyyyMMdd T#HH:mm:ss")
DOpus.OutputString modifiedDateF1 & "- ModDateF1"


			
        clickData.func.command.ClearFiles
        clickData.func.command.AddFile file
		 clickData.func.command.RunCommand "SetAttr META datetaken:" & modifiedDateF1
   Next
End Function

Any suggestions of what else I missed?

If there's a space in a command's arguments/parameters, you need to put quotes around them.

"SetAttr META datetaken:" & modifiedDateF1

will turn into

SetAttr META datetaken:20161106 222130

The time part is just floating there, it won't be associated with the "datetaken:..." part.

Try this:

clickData.func.command.RunCommand "SetAttr META ""datetaken:" & modifiedDateF1 & """"

which will generate a command line like this:

SetAttr META "datetaken:20161106 222130"

Awesome, thank you loe and jon!! I now have a perfectly working script that i'm fairly confident will not much up my files.

I have two last (hopefully) follow up question if anyone knows the answer to:

  1. I had some issues where the File Name Date will carry-over from a previous file if the next file did not have a date in the file name. I ended up resetting the fileNameDate to "Blank" every iteration by using "fileNameDate = Empty". I found that you can use either Empty, Null, or Nothing to do pretty much the same thing but it could have slightly different effects. Even though I'm not experiencing any issues with using "Empty", I was just curious if anyone has feedback about using something else instead.

  2. When running my script on a batch of files that happened to contain a pdf, I received an error half way "Object doesn't support this property or method: 'file.metadata.image' (0x800a01b6)". I guess this makes sense since .pdf file does not have a Date Modified tag. However, why does it work fine for all video, gif, xls, txt, wav and other file types without Date Taken tag? It not a big deal because I will mostly be updating image and video tags, but if a pdf file (or possibly other unsupported type) gets caught, it does not finish the remaining files and I will not know if and where it stopped and what files have been updated. Is there a relatively easy way to add something to the code to skip these types of exceptions or unsupported files and complete all selected files?

  3. This is actually most important. I found a workaround to being able to fully preview (almost) changes before making them by commenting out the RunCommand lines and adding a healthy dose of Output string in the debug log. It actually came out really nice (goo.gl/hDIbRC), but a) you have to comment out the CMD tags each time and b) you have to go into Customize mode and run the script from "Run" command rather than directly from Button. I guess i can make One button with those tagged out and call it "Preview", but what about the detailed Output? Is there any way to have it pop out or be displayed somewhere without having to go into Customize mode?

For anyone curious about using the same of variation of the code I am referring to, see below. Just make sure to untag the RunComman lines if you actually want to make changes.

The idea of the code is to update Date Take, Date Digitized, and Date Modified on a file using the Date in name of the file. However, it will check to make sure Date Take or Date Digitized does not already exist. Then it checks to make sure the Date it the file name is not greater than the date in the Last Modified Date Tag, if it is, then there is something wrong with the naming and it will skip updating that file.

Option Explicit
Function OnClick(ByRef clickData)

	Dim file, files, countFiles, countUpdated ,countSkip, countReview
	Set files = clickData.func.sourcetab.selected_files 
	countFiles = 0
	countUpdated = 0
	countSkip = 0 
	countReview = 0

	For Each file in files
		Dim fileName, modifiedDate, imgTaken, imgDigitized, regex0, fileNameDate
		countFiles = countFiles + 1
		fileName = file.name
		modifiedDate = file.modify.Format("D#yyyyMMdd T#HH:mm:ss")
		imgTaken = file.metadata.image.datetaken
		imgDigitized = file.metadata.image.datedigitized
				
		Set regex0 = new RegExp
		regex0.Pattern = ".*(20[0-2][0-9])\D?([0-1][0-9])\D?([0-3][0-9])\D?([0-2][0-9])\D?([0-5][0-9])\D?([0-5][0-9]).*"
		
		If (regex0.Test(fileName)) Then
			fileNameDate = regex0.Replace(fileName, "$1$2$3 $4:$5:$6")
		Else
			fileNameDate = Empty
		End If

 		DOpus.OutputString "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
		DOpus.OutputString "               Name: (" & fileName & "), Name Date: (" & fileNameDate & "), Type: (" & file.metadata & "), Modified: (" & modifiedDate & "), Img Taken: (" & imgTaken & "), Img Digitized: (" & imgDigitized & ")"	
        
		If (Not IsEmpty(fileNameDate)) Then
			If (IsEmpty(imgTaken)) Then
				If (IsEmpty(imgDigitized)) Then
					If (fileNameDate <= modifiedDate) Then
					DOpus.OutputString "Updated        File Name Date less than Modified Date and No Date Taken or Date Modified: UPDATE EXIF Date in File Name - Updated"
						clickData.func.command.ClearFiles
						clickData.func.command.AddFile file
						'clickData.func.command.RunCommand "SetAttr META " & """datetaken:" & fileNameDate & """" & " " & """datedigitized:" & fileNameDate & """" & " " & """lastmodifieddate:" & fileNameDate & """"
						countUpdated = countUpdated + 1
					Else
						DOpus.OutputString "*** REVIEW *** - DO NOT UPDATE: File Name Date is Newer than Date Modified - *** REVIEW ***"
						countReview = countReview + 1
					End if
				Else
					DOpus.OutputString "*** REVIEW *** - DO NOT UPDATE: Image Date Taken is Empty but Image Date Digitized Exists - *** REVIEW ***"
					countReview = countReview + 1
				End if
			Elseif (Not IsEmpty(imgDigitized)) Then
				DOpus.OutputString "Skip           Image Date Taken and Image Date Digitized Exists - Do Not Update"
				countSkip = countSkip + 1
			Elseif (IsEmpty(imgDigitized)) Then
				DOpus.OutputString "*** REVIEW *** DO NOT UPDATE: Image Date Taken Exists but Image Date Digitized is Empty - *** REVIEW ***"
				countReview = countReview + 1
			End if
		Elseif (IsEmpty(imgTaken)) Then

				If (IsEmpty(imgDigitized)) Then
				DOpus.OutputString "Updated        No File Date, Image Taken, and Image Digitized: Update Taken and Digitized with Modified Date - Updated"
						clickData.func.command.ClearFiles
						clickData.func.command.AddFile file
						'clickData.func.command.RunCommand "SetAttr META " & """datetaken:" & modifiedDate & """" & " " & """datedigitized:" & modifiedDate & """"	
						countUpdated = countUpdated + 1
				Else
					DOpus.OutputString "*** REVIEW *** DO NOT UPDATE: Image Date Digitized Exists but No Date Taken - *** REVIEW ***"
					countReview = countReview + 1
				End if
		Elseif (Not IsEmpty(imgDigitized)) Then
			DOpus.OutputString "Skip           No Date in File Name but Image Date Taken and Date Digitized Exists - Skip"
			countSkip = countSkip + 1
		End if
	Next
	DOpus.OutputString "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
	DOpus.OutputString ""
	DOpus.OutputString "Total Files: (" & countFiles & ") - Updated: (" & countUpdated & "), Skipped: (" & countSkip & "), Need Review: (" & countReview & ")"
End Function
  1. Check whether there is an object in metadata.image for each file to prevent the exceptions and leave the function or the core of it if there is none.

  2. You could test for a qualifier to be pressed and only do harmful things in this case, else just preview/dump your text. Check the clickdata.func.qualifiers property for this. The output should always be visible in the "Other Logs" utility panel / script console as well. No need for customize mode every time.

Thanks tbone!

  1. Sorry, but can you help with how to write this check?

  2. I was able to rework this example ([FR] Scripting - qualifiers for all events?) and just put the 3 clickdata functions inside of it. Seems to work as expected :slight_smile: The "Other Logs" view also works great for me now, the only issue is that it stores only only about 250 lines in history. I found if I change the setting "Maximum size of FTP Logs" to max of 1024KB (unfortunately it reverts back to that number if you make it bigger), I'm able to keep up to 4k lines (depending on amount of output text) in the view which should be enough.

BTW - This is what I have now to only fire on shift hold:

 If (InStr(clickData.func.qualifiers, "shift") > 0) Then
              clickData.func.command.ClearFiles
              clickData.func.command.AddFile file
              clickData.func.command.RunCommand "SetAttr META " & """datetaken:" & modifiedDate & """" & " " & 
  End If
  1. It should be as simple as "if file.metadata.image then.. ".

  2. Looks good. o)

Haaaaaaaallelujah! LOL! Looks like 10th time is a charm... :thumbsup:

I tried that variation as well as a bunch of others but they all still had to evaluate file.metadata.image to know it exists or is empty and that's when it gave the property not supported error. So I also tried dropping the image criteria to see if it was able to test for meta tags in general and that seemed to work (last one in list below). BTW, I realized this error usually occurred on corrupt files that may not have any meta tags (and usually have no Document Created Date tag).

'If file.metadata.image then
'If (NOT IsEmpty (file.metadata.image)) then
'If (NOT IsNull (file.metadata.image)) then
'If (NOT IsNothing (file.metadata.image)) then
'If file.metadata.image= True then
'If file.metadata then
'If (NOT IsEmpty (file.metadata)) then
'If (NOT IsNull (file.metadata)) then
'If (NOT IsNothing (file.metadata)) then
If file.metadata = True then

Doh! Nevermind, it doesn't work because it all assumes its False and goes to the Else statement...

So you are happy now? Not sure whether there's another question in your response or not. o)

Well I guess I can get around this by using the "If file.metadata = "image" Then" to define the Date Taken and Date Digitized tags inside and then everything else around it (because I will also need to update tags on Videos and Audio). Will have to rewrite the whole script though but should be ok. Also, I can't use else statement to locate all those corrupt files without metadata...

This makes me think of the next steps to figure out how to create a list and add all the files names to it that meet a criteria so that I can print it out in the log after updating. i.e. myList = badFiles > addto.myList = File Name > DOpus.Output myList... But all this is for another time...

Based on some good feedback in other threads from jon, leo, and tbone, I improved the script a little more. I use the log panel to print a preview of changes and then paste them into excel to easily sort and review. Also, it's a great way to save for backup before making updates (goo.gl/ld1HVx)

Option Explicit
Function OnClick(ByRef clickData)

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

	If (InStr(clickData.func.qualifiers, "shift") > 0) Then
		liveStatus = " - SHIFT held during operation: All Chnages are LIVE"
	End If
	
	DOpus.OutputString "Number; File Name; File Name Date; Modified Date; Date Taken; Date Digitized; File Type; Status; Reason"
	
	For Each file in files
		Dim fileName, fileType, modifiedDate, imgTaken, imgDigitized, regex0, fileNameDate, metaString
		countFiles = countFiles + 1
		fileName = file.name
		fileType = file.metadata
		fileNameDate = Empty
		imgTaken = Empty
		imgDigitized = Empty
		modifiedDate = file.modify.Format("D#yyyyMMdd T#HH:mm:ss")	
	
		Set regex0 = new RegExp
		regex0.Pattern = ".*(20[0-2][0-9])\D?([0-1][0-9])\D?([0-3][0-9])\D?([0-2][0-9])\D?([0-5][0-9])\D?([0-5][0-9]).*"
		If (regex0.Test(fileName)) Then
			fileNameDate = regex0.Replace(fileName, "$1$2$3 $4:$5:$6")
		End If
		
		If file.metadata = "image" Then
			imgTaken = file.metadata.image.datetaken
			If (Not IsEmpty(imgTaken)) Then
				imgTaken = DOpus.Create.Date(imgTaken).Format("D#yyyyMMdd T#HH:mm:ss")
			End If
			imgDigitized = file.metadata.image.datedigitized
			If (Not IsEmpty(imgDigitized)) Then
				imgDigitized = DOpus.Create.Date(imgDigitized).Format("D#yyyyMMdd T#HH:mm:ss")
			End If
		End if
		
		If file.metadata = "image" Then 
			If (Not IsEmpty(fileNameDate)) Then
				If (IsEmpty(imgTaken)) Then
					If (IsEmpty(imgDigitized)) Then
						metaString = fileName & "; " & fileNameDate & "; " & modifiedDate & "; " & imgTaken & "- ; " & imgDigitized & "- ; " & fileType
						If (fileNameDate <= modifiedDate) Then
							'Image, YES File_Name_Date, NO Image_Taken, NO Image_Digitized, File_Name_Date <= Modified_Date - Update Image_Taken, Image_Digitized, and Modified_Date with File_Name_Date - Update
							DOpus.OutputString countFiles & "; " & metaString & "; Update; 1"
							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:" & fileNameDate & """" & " " & """datedigitized:" & fileNameDate & """" & " " & """lastmodifieddate:" & fileNameDate & """"
							End If
						Else
							'Image, YES File_Name_Date, NO Date_Taken, NO Date_Digitized, File_Name_Date > Modified_Date - Review
							DOpus.OutputString countFiles & "; " & metaString & "; Review; 2"
							countReview = countReview + 1
						End if
					Else
						metaString = fileName & "; " & fileNameDate & "; " & modifiedDate & "; " & imgTaken & "- ; " & imgDigitized & "; " & fileType
						'Image, YES File_Name_Date, NO Date_Taken, YES Date_Digitized - Review
						DOpus.OutputString countFiles & "; " & metaString & "; Review; 3"
						countReview = countReview + 1
					End if
				Elseif (Not IsEmpty(imgDigitized)) Then
					metaString = fileName & "; " & fileNameDate & "; " & modifiedDate & "; " & imgTaken & "; " & imgDigitized & "; " & fileType
					'Image, YES File_Name_Date, YES Date_Taken, YES Date_Digitized - Skip
					DOpus.OutputString countFiles & "; " & metaString & "; Skip; 4"
					countSkip = countSkip + 1
				Else
					metaString = fileName & "; " & fileNameDate & "; " & modifiedDate & "; " & imgTaken & "; " & imgDigitized & "- ; " & fileType
					'Image, YES File_Name_Date, YES Date_Taken, NO Date_Digitized - Review
					DOpus.OutputString countFiles & "; " & metaString & "; Review; 5"
					countReview = countReview + 1
				End if
			Else
				If (IsEmpty(imgTaken)) Then
					If (IsEmpty(imgDigitized)) Then
						metaString = fileName & "; " & fileNameDate & "- ; " & modifiedDate & "; " & imgTaken & "- ; " & imgDigitized & "- ; " & fileType
						'Image, NO File_Name_Date, NO Date_Taken, NO Date_Digitized - Update Date_Taken, Date_Digitized with Modified_Date - Update
						DOpus.OutputString countFiles & "; " & metaString & "; Update; 6"
						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:" & modifiedDate & """" & " " & """datedigitized:" & modifiedDate & """"	
							clickData.func.command.RunCommand "SetAttr META datetaken:lastmodifieddate datedigitized:lastmodifieddate"
							'clickData.func.command.RunCommand "SetAttr META datetaken:lastmodifieddate"
						End If
					Else
						metaString = fileName & "; " & fileNameDate & "- ; " & modifiedDate & "; " & imgTaken & "- ; " & imgDigitized & "; " & fileType
						'Image, NO File_Name_Date, NO Date_Taken, YES Date_Digitized - Review
						DOpus.OutputString countFiles & "; " & metaString & "; Review; 7"
						countReview = countReview + 1
					End if
				Elseif (Not IsEmpty(imgDigitized)) Then
					metaString = fileName & "; " & fileNameDate & "- ; " & modifiedDate & "; " & imgTaken & "; " & imgDigitized & "; " & fileType
					'Image, NO File_Name_Date, YES Date_Taken, YES Date_Digitized - Skip
					DOpus.OutputString countFiles & "; " & metaString & "; Skip; 8" 
					countSkip = countSkip + 1
				Else
					metaString = fileName & "; " & fileNameDate & "- ; " & modifiedDate & "; " & imgTaken & "; " & imgDigitized & "- ; " & fileType
					'Image, NO File_Name_Date, YES Date_Taken, NO Date_Digitized - Review
					DOpus.OutputString countFiles & "; " & metaString & "; Review; 9"
					countReview = countReview + 1
				End if
			End if
		Else
			If (Not IsEmpty(fileNameDate)) Then
				metaString = fileName & "; " & fileNameDate & "; " & modifiedDate & "; " & imgTaken & "- ; " & imgDigitized & "- ; " & fileType 
				If (fileNameDate < modifiedDate) Then			
					'Other, YES File_Name_Date, File_Name_Date < Modified_Date - Update Modified_Date with File_Name_Date
					DOpus.OutputString countFiles & "; " & metaString & "; Update; 10"
					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 " & """lastmodifieddate:" & fileNameDate & """"
					End If
				Elseif (fileNameDate = modifiedDate) Then
					'Other, YES File_Name_Date, File_Name_Date = Modified_Date - Skip
					DOpus.OutputString countFiles & "; " & metaString & "; Skip; 11"
					countSkip = countSkip + 1
				Else
					'Other, YES File_Name_Date, File_Name_Date > Modified_Date - Review
					DOpus.OutputString countFiles & "; " & metaString & "; Review; 12"
					countReview = countReview + 1
				End if
			Else
				metaString = fileName & "; " & fileNameDate & "- ; " & modifiedDate & "; " & imgTaken & "- ; " & imgDigitized & "- ; " & fileType 
				'Other, NO File_Name_Date, Retain Modified_Date - Skip
				DOpus.OutputString countFiles & "; " & metaString & "; Skip; 13"
				countSkip = countSkip + 1
			End if
		End if
		
	Next
	DOpus.OutputString "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
	DOpus.OutputString "Total Files: (" & countFiles & ") - Update: (" & countUpdate & "), Skip: (" & countSkip & "), Need Review: (" & countReview & ")" & liveStatus

End Function

Quick question about different formatting I have seen and best practice:

When declaring a variable to blank before a loop, it is sometimes done as "" or Empty. Also, when checking the value, it is sometimes used with "(Not IsEmpty(variable))" and "variable <> Empty". IS it better to use one vs another?

Ex1:
fileNameDate = Empty
or
fileNameDate = ""

Ex2:
If (Not IsEmpty(fileNameDate)) Then
or
If fileNameDate <> Empty Then
or
If fileNameDate <> "" Then

w3schools.com/asp/func_isempty.asp
stackoverflow.com/questions/4060 ... n-vbscript

more:
google.de/search?q=vbs+empty+string+IsEmpty

It's a good idea to ask the internet for this type of questions first, it's all been questioned and answered a zillion times. o)
If you have special issues with syntax, with operators e.g., it's worth searching with "http://www.symbolhound.com", as this search engine is optimized for finding weird combinations of characters, like it happens in source code.

Thanks tbone. I just wasn't sure initially what is specific to Dopus only and what is generally available in VBscript since I am very new to both. Now it i'm getting the hang of it.

All I want to do is change the modified date from the date in the file name. Big ask: could someone delete all the code that is not needed in order to just change the modified date? TIA

The 3rd (now 4th) thread currently on the front page of the forum is exactly about that: File name to modified date/time?

Here is what I wanted:

Clipboard COPYNAMES=nopaths REGEXP ".*(\d\d\d\d-\d\d-\d\d)..*" "\1"
/home\dopusrt.exe /cmd SetAttr MODIFIED "{clip}"type or paste code here

That will overwrite any information in your clipboard. The method in the other thread won't do that.

It'll also only work on a single file at a time, while the method I linked to works with multiple files.