Script for rename

Advanced Renamer forum
#1 : 21/02-15 22:48
chai
chai
Posts: 1
Hi Guys -

I am trying to rename my file in the way below.

My current file name includes the name twice, so if the name is happy, my file name is happyhappy. Its for all files and I am finding it tough to get it to a single string.

here are the examples of file names i have

TelevisionTelevision
phonephone
remoteremote
laptoplaptop

I need a script to rename it as below -

Television
phone
remote
laptop

Please help!

Thank You,

Chai


21/02-15 22:48
#2 : 25/03-15 22:00
NomenEtOmen
NomenEtOmen
Posts: 29
Reply to #1:
hi,
try following, applying on "Name":

it first gets the name
then checks if length is even (should be by duplicated names)
then calculates the half
then extracts the first half
then checks if first half is eqal the second half
if ok then returns the half
:-)



var nName = ""; // new name
var oName = item.name; // original name
var iLength = oName.length // length of original file name


if (iLength%2==0) { //test MODULO 2 ok
iLength = iLength / 2;
} else {
//not even: quit without result
return;
}

nName = oName.substring(0,iLength); //first half

if (nName==oName.substr(iLength,iLength)) {
//second half is identical with first half :-)
return nName;
} else {
//not identical: quit without result
return;
}


25/03-15 22:00 - edited 25/03-15 22:01
#3 : 25/03-15 22:13
Tester123
Tester123
Posts: 92
Reply to #1:

An alternative approach (but using built-in functionality rather than a script as requested/suggested):

Replace Method:
--------------------
Text to be replaced: (.{3,})\1
Replace with: \1
Case sensitive: Tick
Use regular expressions: Tick
Apply to: Name

This looks for a string that is at least 3 characters long (excluding the duplicate), which is repeated (that's what the \1 in the "Text to be replaced" is for).

Hope that helps.


25/03-15 22:13 - edited 25/03-15 22:14