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:
-
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.
-
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?
-
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