Below is small test script to print out all files on D: with the tags. Each filename is output OK but no tags are output. What am I doing wrong ?
var items = DOpus.FSUtil.ReadDir("D:\\", false);
while (!items.complete) {
var item = items.Next;
if (!item.is_dir) {
DOpus.Output(item);
var tag;
for (tag in item.metadata.tags) {
DOpus.Output(tag);
}
}
}
DOpus.Output("Done");
Just read the manual about Opus returning a DOpus.Vector object for collections, and obviously JScript cannot iterate over the elements. After changing it to following, it works:
DOpus.ClearOutput;
var items = DOpus.FSUtil.ReadDir("D:\\", false);
while (!items.complete) {
var item = items.Next;
if (!item.is_dir) {
DOpus.Output(item);
// There may not be any tags, so check if tag collection exists before enumerating
var tags = item.metadata.tags;
if (tags) {
var numTags = tags.count;
var i = 0;
while (numTags--) {
DOpus.Output(tags(i++));
}
}
}
}
DOpus.Output("Done");
I tried using if (!tags.empty) and if (tags.empty == false) instead of tags.count to check if there were any tags, but I couldn't get it to work. How do you use tags.empty ?
Also, I was expecting that if a valid metadata object was returned for a file, there would be a valid tags object, but this was not the case for one of my test files. So, the following code fragment produced an error when retrieving the number of tags for the file in question:
var metadata = item.metadata;
if (metadata) {
var numTags = metadata.tags.count;
My JScript knowledge is suspect, at best, so I adapted your code into VBScript. The following works for me.
[code]@language VBScript
Dim items, item, i, meta
Set items = DOpus.FSUtil.ReadDir("C:\Test", False)
On Error Resume Next
Do While Not (items.complete)
Set item = items.Next
If Not (item.is_dir) Then
Set meta = item.metadata
If meta.tags.count > 0 Then
DOpus.Output "Item = " & item & " tags.count = " & meta.tags.count
For i=1 To meta.tags.count
DOpus.Output "tag(" & i & ") " & meta.tags(i-1)
Next
End If
End If
Loop
Note the inclusion of an "On Error Resume Next" statement to deal with files that throw an error when attempting to interrogate metadata. See this post for a report regarding .osp files. Other file types may also be affected. My testing was not extensive.
Collections* and DOpus.Vectors are different things.
(* In the scripting context. File Collections in Opus itself are yet another thing, of course.)
The docs say metadata.tags gives you a collection:string ("collection of strings"), so DOpus.Vector is not relevant here.
Collections don't have empty or count methods, at least not in JScript. (How collections work is up to the scripting language, so those methods might exist in other languages.)