I haven't been around for a while, so I'm excited (and surprised) to see all this talk about custom columns. It could solve a sorting issue I've been battling for quite a long time.
Can someone help me with a script that will pull any text inside () at the end of a filename, and pop it into a sort-able column?
' Called by Directory Opus to initialize the script
Function OnInit(initData)
initData.name = "Brackets Column"
initData.desc = "Extract stuff in brackets at the end of filenames"
initData.copyright = "(C) 2015 Leo Davidson"
initData.version = "1.0"
initData.default_enable = true
Dim col
Set col = initData.AddColumn
col.name = "Brackets"
col.method = "OnBrackets"
col.label = "Brackets"
col.justify = "left"
col.autogroup = true
End Function
' Implement the Brackets column
Function OnBrackets(scriptColData)
If (scriptColData.col <> "Brackets") Then
Exit Function
End If
If (re Is Nothing) Then
' re made the first time the column is requested, then cached.
Set re = new RegExp
re.pattern = "^.*(([^()]+))$"
End If
If (re.Test(scriptColData.item.name_stem)) Then
scriptColData.value = re.Replace(scriptColData.item.name_stem, "$1")
End If
End Function[/code]
All the boilerplate (almost everything except the body of "OnBrackets") can be made for you via File > New Script in the Preferences dialog, when on the Toolbars / Scripts page.
Thanks Leo, this works real nice!
MY folders don't have the info in the parentheses in the end, but actually it's right before the end. Is it possible to modify the script so that it works for that setup as well?
For example, my folders look like this: "Double Indemnity (1944) [720p]". Perhaps the script can create a column for both, what's in parentheses and what's in the brackets...
Looking fw to your thoughts!
AR
You might also want to look at these existing script add-ins, some of which let you configure multiple columns without editing script code (but still requiring you to understand regexps):
Hi Leo,
I just tried it and it works beautifully! Thank you so much!
Is there some place I can add:
re.pattern = "^.[(.+)].$"
So that it it extracts what's in both the parentheses AND in the Brackets and creates a column for each at the same time?