CASE (4), toggle button, ignore mulitpl capital letters

Would you like Bulk Rename Utility to offer new functionality? Post your comments here!

CASE (4), toggle button, ignore mulitpl capital letters

Postby angeltread » Thu Jul 10, 2025 1:34 am

be nice if the Case (4) section, if there was a toggle button to turn on and it would then ignore any existing words that have multiple (2 or more) capital letters within.

i need to use the "Title" functionality often but can't cause i have filenames that have Acronyms that are all Caps or two word names sometimes made into one word and there is two capitals within it showing first and last name, but its one word.
a simple toggle button for "ignore words with multiple capital letters" would be wondrous.
angeltread
 
Posts: 11
Joined: Fri Aug 07, 2020 12:03 am

Re: CASE (4), toggle button, ignore mulitpl capital letters

Postby Admin » Thu Jul 10, 2025 2:20 am

Thank you for posting on the forum. Could you give some examples of file name before / after ? thanks!
Admin
Site Admin
 
Posts: 2982
Joined: Tue Mar 08, 2005 8:39 pm

Re: CASE (4), toggle button, ignore mulitpl capital letters

Postby angeltread » Thu Jul 10, 2025 3:20 am

so a file name like...

JohnDenver - Live at MSG - country roads.mp3

currently if i were change the CASE (4) to "Title"
it would give me...

Johndenver - Live At Msg - Country Roads.mp3

but if i did "Title" again and it had a toggle to "ignore words with multiple capital letters"

i could get

JohnDenver - Live At MSG - Country Roads.mp3

which is what i would want.
angeltread
 
Posts: 11
Joined: Fri Aug 07, 2020 12:03 am

Re: CASE (4), toggle button, ignore mulitpl capital letters

Postby Admin » Thu Jul 10, 2025 5:52 am

Code: Select all
JohnDenver - Live at MSG - country roads.mp3
to
JohnDenver - Live At MSG - Country Roads.mp3

Capitalize each word in file name ( first character = title case ) and lower case the rest of the word, but 
if there is an other capital letter present within that word (not in first place), do not lower case its case.
Do not capitalize minor words ( a, an, and, as, at, but, by, en, for, if, in, nor, of, on, or, per, the, to, v, vs, via are not capitalized unless they are at the start or at the end of a sentence )


Javascript (copy and paste in BRU javascript):

Code: Select all
// Example:
// name = "JohnDenver - Live at MSG - country roads"
// newName = "JohnDenver - Live At MSG - Country Roads"

// List of minor words (not capitalized unless at start or end)
var minorWords = [
  "a", "an", "and", "as", "at", "but", "by", "en", "for", "if", "in", "nor",
  "of", "on", "or", "per", "the", "to", "v", "vs", "via"
];

// Helper: checks if word has any uppercase letter after the first character
function hasInnerUpper(word) {
  return /[A-Z]/.test(word.slice(1));
}

// Helper: capitalize first letter, keep rest as is (unless no inner uppercase, then lower rest)
function smartCap(word) {
  if (!word) return word;
  if (hasInnerUpper(word)) {
    // Only capitalize first letter, keep rest as is
    return word.charAt(0).toUpperCase() + word.slice(1);
  } else {
    // Capitalize first, lower rest
    return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
  }
}

// Split name into tokens (words and separators)
var tokens = [];
var re = /([A-Za-z0-9]+|[^A-Za-z0-9]+)/g;
var m;
while ((m = re.exec(name)) !== null) {
  tokens.push(m[0]);
}

// Find word token indexes for start/end logic
var wordIndexes = [];
for (var i = 0; i < tokens.length; i++) {
  if (/^[A-Za-z0-9]+$/.test(tokens[i])) wordIndexes.push(i);
}

// Transform tokens
for (var i = 0; i < tokens.length; i++) {
  if (/^[A-Za-z0-9]+$/.test(tokens[i])) {
    var word = tokens[i];
    var isFirst = (i === wordIndexes[0]);
    var isLast = (i === wordIndexes[wordIndexes.length - 1]);
    var lowerWord = word.toLowerCase();
    if (!isFirst && !isLast && minorWords.indexOf(lowerWord) !== -1) {
      // Minor word, not at start/end: keep lowercase
      tokens[i] = lowerWord;
    } else {
      // Capitalize as needed
      tokens[i] = smartCap(word);
    }
  }
}

// Join back
newName = tokens.join("");

Admin
Site Admin
 
Posts: 2982
Joined: Tue Mar 08, 2005 8:39 pm

Re: CASE (4), toggle button, ignore mulitpl capital letters

Postby angeltread » Fri Jul 11, 2025 9:44 pm

dude. thats cool.

one slight thing though is this is for "Title Enhanced" which not only ignore the minor words like "and, the, but, in, etc etc" but will change any of those words to lowercase....
ive been doing all my stuff just pure "Title" where it still does those words. which is what i want.

also when trying to do for a whole batch, it tells me "nope" unless i have commercial license. that's a bummer, its a hundred bucks i dont have now or probably anytime soon. maybe someday though.
angeltread
 
Posts: 11
Joined: Fri Aug 07, 2020 12:03 am

Re: CASE (4), toggle button, ignore mulitpl capital letters

Postby angeltread » Fri Jul 11, 2025 9:46 pm

also im a bit of a laymen. so...
i did the javascript section, which i was able to figure out where that goes...
whats the first section you posted though? im not sure what that part is.
angeltread
 
Posts: 11
Joined: Fri Aug 07, 2020 12:03 am

Re: CASE (4), toggle button, ignore mulitpl capital letters

Postby Admin » Sat Jul 12, 2025 7:44 am

Hi, you only need to paste this into JavaScript in BRU:

Code: Select all
// Example:
// name = "JohnDenver - Live at MSG - country roads"
// newName = "JohnDenver - Live At MSG - Country Roads"

// List of minor words (not capitalized unless at start or end)
var minorWords = [
  "a", "an", "and", "as", "at", "but", "by", "en", "for", "if", "in", "nor",
  "of", "on", "or", "per", "the", "to", "v", "vs", "via"
];

// Helper: checks if word has any uppercase letter after the first character
function hasInnerUpper(word) {
  return /[A-Z]/.test(word.slice(1));
}

// Helper: capitalize first letter, keep rest as is (unless no inner uppercase, then lower rest)
function smartCap(word) {
  if (!word) return word;
  if (hasInnerUpper(word)) {
    // Only capitalize first letter, keep rest as is
    return word.charAt(0).toUpperCase() + word.slice(1);
  } else {
    // Capitalize first, lower rest
    return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
  }
}

// Split name into tokens (words and separators)
var tokens = [];
var re = /([A-Za-z0-9]+|[^A-Za-z0-9]+)/g;
var m;
while ((m = re.exec(name)) !== null) {
  tokens.push(m[0]);
}

// Find word token indexes for start/end logic
var wordIndexes = [];
for (var i = 0; i < tokens.length; i++) {
  if (/^[A-Za-z0-9]+$/.test(tokens[i])) wordIndexes.push(i);
}

// Transform tokens
for (var i = 0; i < tokens.length; i++) {
  if (/^[A-Za-z0-9]+$/.test(tokens[i])) {
    var word = tokens[i];
    var isFirst = (i === wordIndexes[0]);
    var isLast = (i === wordIndexes[wordIndexes.length - 1]);
    var lowerWord = word.toLowerCase();
    if (!isFirst && !isLast && minorWords.indexOf(lowerWord) !== -1) {
      // Minor word, not at start/end: keep lowercase
      tokens[i] = lowerWord;
    } else {
      // Capitalize as needed
      tokens[i] = smartCap(word);
    }
  }
}

// Join back
newName = tokens.join("");


For Javascript funtionality you will need a license but there's also the home license avail which is cheaper.
Admin
Site Admin
 
Posts: 2982
Joined: Tue Mar 08, 2005 8:39 pm


Return to Suggestions


cron