removing repeating name patterns with batch rename method?

Advanced Renamer forum
#1 : 05/06-24 13:36
raf
raf
Posts: 12
This is a tricky one.

I need to remove repeating patterns

Say i have a number of files with common repeating text patterns in the filename.

For instance:
filename_abc_123
filename_def_123
filename_ghi_456

The output should be
filename_abc
filename_def
filename_ghi_456

AR scans for repeating patterns and removes common patterns

How would i achieve this?


05/06-24 13:36
#2 : 05/06-24 14:21
Delta Foxtrot
Delta Foxtrot
Posts: 264
Reply to #1:

Hi Raf,

I can't think of a way to do that in ARen, since there's no comparison function that works between the different filenames (that I know of, anyway). Even scripting in ARen won't let you do that (again, as far as I know). Maybe if you have scripting knowledge you could put the filenames into arrays, separating the parts of the filenames after the first underscore, then do comparisons between the different arrays and array elements. You could then write out a csv or text file that could be loaded into ARen to do the actual renames, saving you some scripting work. Might be a good time to look at something like AutoHotkey or python.

On the other hand, maybe someone with more skillz will be able to tell you how to do it in Aren. Good luck!

Best,
DF


05/06-24 14:21
#3 : 05/06-24 14:38
raf
raf
Posts: 12
Reply to #2:
thanks! I will look into python!


05/06-24 14:38
#4 : 25/06-24 22:27
Delta Foxtrot
Delta Foxtrot
Posts: 264
Reply to #3:

Hello raf,

I don't know if you are around to read this, but maybe it will help you or someone else.

In thinking about your problem (I get bored :) I realized it was reasonably trivial in javascript.

Using your exact filename examples, this is how you can do it (you may need to modify it depending on your real file set; let me know if I can help):

PRE-BATCH SCRIPT:

// Array to hold filename part 2:
const partArr = [] ;
// Separate out last part to array for comparison with indexOf() and lastIndexOf():
for (n=0; n<app.itemCount; n++) partArr[n] = app.getItem(n).name.match(/_\d*?$/)[0] ;


SCRIPT:

var returnStr = item.newBasename;
var testPart = app.parseTags( "_" + '<rsubstr:1:"_">' ) ;
var fn = item.newBasename ;
if (partArr.indexOf(testPart) < partArr.lastIndexOf(testPart)) {
returnStr = fn.replace( testPart, "" );
}
return returnStr ;

--------------------------------------------------------------------------
EDIT: I changed the main script a little to simplify END EDIT

So all I did was create an array with all the filename tail-ends in the pre-batch, then compare the indexOf() and lastIndexOf(() each tail-end in the array. If they were different I stripped that part from the return string.

EDIT: Screenshot: https://drive.google.com/file/d/1oFKS-zY7SuM2C1A -wN-QMpDzIetiAEjT/view?usp=sharing
END EDIT

Sorry it took me so long to come to my senses! :)

Best,
DF


25/06-24 22:27 - edited 25/06-24 22:34