RegExp to capitalize all words in filename, without modifying existing camelCase or HumpCase words

Can anyone please help me out with an RegExp rename example to capitalize all the words in a filename, but without modifying existing camelCase or HumpCase words?

this is partOne and this is PartTwo.ext -->
This Is partOne And This Is PartTwo.ext

Google's Bard tells me this should work:

Rename WHENEXISTS=rename PATTERN="/a-z(?=[a-z])/g" TO="\1" REGEXP IGNOREEXT NOMATCHNOFAIL

but it doesn't. I've been trying to work it out using Bard's example as a starting point, but I'm in over my head.

Thank you for reading and for any help you may be able to provide, cheers!

Opus' regex dialect doesn't support capitalization. But a rename script is not too difficult.

// https://resource.dopus.com/t/regexp-to-capitalize-all-words-in-filename-without-modifying-existing-camelcase-or-humpcase-words/46680

function OnGetNewName(getNewNameData) {
    var allWords = getNewNameData.newname.split(' ');
    for (var i = 0; i < allWords.length; i++) {
        if (allWords[i].substring(1).match(/.*[A-Z].*/)) continue;
        allWords[i] = allWords[i].substring(0, 1).toUpperCase() + allWords[i].substring(1);
    }
    return allWords.join(' ');
}

Save 46680.orp to   ↓

%appdata%\GPSoftware\Directory Opus\Rename Presets

How to use buttons and scripts from this forum

4 Likes

Thank you so much, that works perfectly! I really appreciate your help. @lxp