Remove the second repetition of filename from the filename.

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Remove the second repetition of filename from the filename.

Postby arkumar » Fri May 25, 2018 5:14 pm

In a folder i have images and pdf files which have it's file name repeated twice.

541-200-6_web_ad541-200-6_web_ad.jpg
OApatchOApatch.png
oldbookoldbook.jpg

I want to rename them like
541-200-6_web_ad.jpg
OApatch.png
oldbook.jpg
I have more than 3000 files with this issue.
arkumar
 
Posts: 1
Joined: Fri May 25, 2018 5:08 pm

Re: Remove the second repetition of filename from the filename.

Postby therube » Fri May 25, 2018 8:23 pm

Take the length of the filename, divide by 2.
Cut the filename at answer+1.

I'm sure you could do that with the JavaScript Renaming feature, but that's beyond me.
therube
 
Posts: 693
Joined: Mon Jan 18, 2016 6:23 pm

Re: Remove the second repetition of filename from the filename.

Postby Admin » Sat May 26, 2018 1:20 am

This is the javacript equivalent:

Code: Select all
newName = name.substr(name.length/2);


You can use it in BRU with the Javascript renaming functionality.

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

Re: Remove the second repetition of filename from the filename.

Postby JeffJCal » Sun Nov 17, 2019 4:58 am

Hi, What if the repetition is not midway but something like:

PDF for dummies get started by reading this ebook PDF for Dummies is all you need.pdf

but the problem is there are hundreds of files with different titles so I cant just crop or REMOVEn from the end.

Great program BTW the latest version seems cluttered though. I dont like the layout.
JeffJCal
 
Posts: 1
Joined: Sun Nov 17, 2019 4:52 am

Re: Remove the second repetition of filename from the filename.

Postby therube » Sun Nov 17, 2019 3:32 pm

The problem as I see it is you may not have anything to "key in to" to know where the "duplicated" part is.

In any case, this thread may be of interest, viewtopic.php?f=3&t=3898.


---


Suppose, you could...

read each word in the filename into an array
(slide) step through the array, one by one looking a matching word later in the array
then proceeding to see if the next, then next ... words also compare
you could set a minimum number of word matches required & truncate at that point

> PDF for dummies get started by reading this ebook PDF for Dummies is all you need.pdf

if set to 3 matches...
so PDF finds PDF, then for finds for, then dummies finds Dummies

depending on your code, you could then truncate at that point

> PDF for dummies get started by reading this ebook.pdf

or remove the matched segment

> PDF for dummies get started by reading this ebook is all you need.pdf


I'd think you could do something like that with JavaScript renaming.
therube
 
Posts: 693
Joined: Mon Jan 18, 2016 6:23 pm


Return to Javascript Renaming