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: 1314
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: 2343
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: 1314
Joined: Mon Jan 18, 2016 6:23 pm

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

Postby bru » Sun Feb 09, 2020 7:01 pm

@JeffJCal

#1Regex Match/Replace:
^(?i)(.*? *(.{8,}).*?)\2(.*)$
\1\3

It removes the 1st-repeating word/phrase of 8-or-more chars (including spaces) anywhere in filename.
Its case-insensitive to match both 'PDF for dummies' and 'PDF for Dummies'
If that was just a typo, you can remove (?i) from the match.

Results as below (1-space always preserved if matching phrases mid-name like 2nd-example):
PDF for dummies ... PDF for Dummies is all you need -------> PDF for dummies ... is all you need
AAA any repeated phrase BBB Any Repeated Phrase CCC ----> AAA any repeated text BBB CCC
AAASomeVeryLongWordBBBsomeverylongwordCCC -----------> AAASomeVeryLongWordBBBCCC

Warning:
If you decide to lower the 8-char-minimum with many files, I'd also put the match in #12Filters with RegEX checked.
Then hit F5/refresh to make sure there aren't cases where you want to keep the repeats.
bru
 
Posts: 62
Joined: Wed Jan 31, 2018 7:35 pm


Return to Javascript Renaming


cron