Rename TO CamelCase:
EDIT: greatly simplified the code to make it more useful as a learning tool.
The following rename script is fully explained on this page about DO12 rename scripting.
The script's goal is to convert names such as the-empire-strikes-back to TheEmpireStrikesBack, but it's really an excuse to showcase a cool DO12 feature that allows you to add your own rename parameters in the rename panel's chrome.
The preset is attached (unzip before importing).
Comments welcome!
The code:
// This optional function handles parameter input
// the fields are added to the rename interface
function OnGetCustomFields(getFieldData)
{
// define checkboxes with an initial state
getFieldData.fields.capitalizeFirstLetter = false
getFieldData.fields.splitOnDashes = true
getFieldData.fields.splitOnUnderscores = true
getFieldData.fields.splitOnDots = true
getFieldData.fields.splitOnSpaces = false
// set the labels for the checkboxes
getFieldData.field_labels("capitalizeFirstLetter") = "CapitalizeFirstLetter"
getFieldData.field_labels("splitOnDashes") = "split-on-dashes"
getFieldData.field_labels("splitOnUnderscores") = "split_on_underscores"
getFieldData.field_labels("splitOnDots") = "split.on.dots"
getFieldData.field_labels("splitOnSpaces") = "split on spaces"
}
// This is the renaming function
function OnGetNewName(getNewNameData)
{
// these two fields inherit any renames already done by other
// means (e.g. capitalization)
var stem = getNewNameData.newname_stem
var ext = getNewNameData.newname_ext
// build a delimiter string reflecting the state of the checkboxes
var delimiters = (getNewNameData.custom.splitOnDashes ? "-" : "") +
(getNewNameData.custom.splitOnUnderscores ? "_" : "") +
(getNewNameData.custom.splitOnDots ? "." : "") +
(getNewNameData.custom.splitOnSpaces ? " " : "")
if (delimiters == '') return false
var delimiterRegex = new RegExp("[" + delimiters + "]", 'g')
var newstem = stem.replace(delimiterRegex, '')
if (! getNewNameData.custom.capitalizeFirstLetter) {
newstem = newstem.slice(0,1).toLowerCase() + newstem.slice(1)
}
return newstem + ext
}
CamelCase.zip (994 Bytes)
Rename FROM CamelCase:
See post #7, below.