Help with updating file properties before renaming them

Thanks tbone. I did read the manual portion before but I was trying stupid combination with it, like:
DOpusFactory.Vector.FiletypeGroup(FileName). But it turns out I don't really need this last part so not going to waste anyones time on it. Thanks again all for your help.

Hey jon,

I was just testing the beta 12.2.5 release assuming that the datetaken is now a by default a date ("The Metadata object now returns a Date object for date values (e.g. Metadata.image.datetaken) rather than VT_DATE variants."), but it still gives the same "Object Required" error when applying the .Format to it.

imgTaken = file.metadata.image.datetaken.Format("D#yyyyMMddT#HHmmss")

Seems to work here (at least in my development build; I haven't double-checked with the beta installer):


function OnClick(clickData) { for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext()) { if (!eSel.item().is_dir) { path = eSel.item().RealPath; if (eSel.item().metadata.image.datetaken == null) date = "<no datetaken>"; else date = eSel.item().metadata.image.datetaken.Format("D#yyyyMMddT#HHmmss"); DOpus.Output(path + ": " + date); } } }

Your Jscript worked fine for me too, so not sure if its just the VBscript issue or something else, but here are my results:

goo.gl/TmDyq7

[code]Function OnClick(ByRef clickData)
Dim file, files
Set files = clickData.func.sourcetab.selected_files
For Each file in files
Dim fileName, createdDate, createdDateF, modifiedDate, modifiedDateF, imgTaken, imgTakenF
DOpus.Output "------------"

  fileName = file.name
  DOpus.Output "Name: " & fileName
  createdDate = file.create
  DOpus.Output "Created: " & createdDate
  createdDateF = file.create.Format("D#yyyyMMdd_T#HHmmss")
  DOpus.Output "CreatedF: " & createdDateF
  DOpus.Output ""
  
  modifiedDate = file.modify
  DOpus.Output "Modified: " & modifiedDate
  modifiedDateF = file.modify.Format("D#yyyyMMdd_T#HHmmss")
  DOpus.Output "ModifiedF:" & modifiedDateF
  DOpus.Output ""
  
  imgTaken = file.metadata.image.datetaken
  DOpus.Output "Taken: " & imgTaken
  imgTaken = file.metadata.image.datetaken.Format("D#yyyyMMdd_T#HHmmss")
  DOpus.Output "TakenF: " & imgTakenF

Next
End Function[/code]

Some files won't have a file.metadata.image.datetaken value at all. You need to check if it exists before using it, otherwise there will be an error.

There was also an error on the datetaken.Format line as it was assigning the result to imgTaken again, not imgTakenF.

In VBScript:

if (Not IsEmpty(file.metadata.image.datetaken)) Then imgTaken = file.metadata.image.datetaken DOpus.Output "Taken: " & imgTaken imgTakenF = file.metadata.image.datetaken.Format("D#yyyyMMdd_T#HHmmss") DOpus.Output "TakenF: " & imgTakenF End If

Ah, your right, leo, it works fine. I think the reason I got confused a little is when I tested on a corrupt image that had no metadata and it gave me the error then even with the if statement (goo.gl/BHqaAn). Otherwise, the formatting is fine. Thanks!

The file.metadata.image object may not exist at all, if the file isn't recognised as an image.

What's funny is that the file.metadata.image object seems to exist in all other files live videos and documents (but no results are retrieved). Is there a way to check if metatags exist on a file without trying to parse the results that will result in an error if file does not have metadata?

Try:

If (Not IsEmpty(file.metadata.image)) Then ... End If

If that doesn't work, could you attach one of the files causing the problem so I can try with the same thing?

Unfortunately, it does not work. It looks like during the evaluation stage when it check if it meets the criteria, it give the error instead of going to the if them statement. See here: goo.gl/nrjPna

Here are the files I tested with: drive.google.com/open?id=0B8AeI ... nNXX2QybjQ

[code]Function OnClick(ByRef clickData)
Dim file, files
Set files = clickData.func.sourcetab.selected_files
For Each file in files
Dim fileName, createdDate, createdDateF, modifiedDate, modifiedDateF, imgTaken, imgTakenF

DOpus.Output "------------"
fileName = file.name
DOpus.Output "Name: " & fileName
createdDate = file.create
DOpus.Output "Created: " & createdDate
createdDateF = file.create.Format("D#yyyyMMdd_T#HHmmss")
DOpus.Output "CreatedF: " & createdDateF
DOpus.Output ""

 modifiedDate = file.modify
 DOpus.Output "Modified: " & modifiedDate
 modifiedDateF = file.modify.Format("D#yyyyMMdd_T#HHmmss")
 DOpus.Output "ModifiedF:" & modifiedDateF
 DOpus.Output ""

If (Not IsEmpty(file.metadata.image)) Then
    DOpus.Output fileName & " ----- Contains Metadata" 
Else
	DOpus.Output  fileName & " CORRUPT No Metadata"
End If

Next
End Function[/code]

Check the value of file.metadata first. If it returns "none" it means there is no metadata present at all (and you'll get an error if you try to access any of the sub-objects).

If it returns something else, all of the sub-objects will be valid (even if they contain no data, they'll still exist) and the value will tell you the "primary" type (e.g. "image").

Oh nice! "If (file.metadata = "none") Then" works when testing for metadata. I don't know if fileType is also pulls the same data, but from my testing, "if (fileType = "none") Then" also gave same results.

Thanks!