Add only pairs within a folder

Is there a way to add files within a folder but filter only for pairs?

My scenario is:
I've got a lot of Apple Live photos burried within a database and I'm trying to delete the 2 second video files. I can't just delete all mov files with a small file size as some of these are legit and not associated with the Live photos. However, if I can filter these out can remame them to isolate those mov files that are associated with the Live Photos. It appears as if the software can identify pairs in order to rename them the same. So, I'm wondering if the software can filter them out to only rename those files. Any help would be appreciated. Thanks.
Reply to #1:

Welcome David!

I can probably post a method in a few hours if no one beats me to it (RL takes priority).

Meanwhile, please be more specific. For example, give exact filenames of things to be renamed, versus things not to be.

Regards.
Randy
Reply to #2:
Thanks for the reply! This would be a lot easier to convey if I could paste snips in this forum, but here it goes:

2025-01-11_17-26-21.HEIC*
2025-01-11_17-26-21.MOV*
2025-01-11_19-32-58.MOV
2025-01-11_19-55-24.HEIC*
2025-01-11_19-55-24.MOV*
2025-01-14_06-59-14.HEIC
2025-01-14_06-59-18.HEIC

The Live Photo pairs have astericks at the end (just in this example...they are not really in the filenames). 2025-01-11_19-32-58.MOV is only a 2MB video but it is not part of a Live Photo. If I could isolate the pairs and rename them to append "Pairs" to the filename (* - Pairs.*), I could search for * - Pairs.mov in windows explorer and delete all of them. That would preserve the other MOV files from being deleted.

Renamed to:
2025-01-11_17-26-21 - Pairs.HEIC
2025-01-11_17-26-21 - Pairs.MOV
2025-01-11_19-32-58.MOV
2025-01-11_19-55-24 - Pairs.HEIC
2025-01-11_19-55-24 - Pairs.MOV
2025-01-14_06-59-14.HEIC
2025-01-14_06-59-18.HEIC

That's it. Not sure if I explained that well or not.

Reply to #3:

Hi David,

Here's a generic way to do what you need (although not exactly what you asked for). I don't know of any way to filter file pairs natively in ARen, but through a small javascript method it's simple enough to move all file pairs in a directory to another, user-designated, directory. You can then delete whatever you want and move the remainders wherever you want them.

I will tell you that setting this up is more complex than actually using it, so if you do use it set it up carefully (and always remember ARen's superlative "undo batch" facility). I'd recommend waiting to see if Randy has a better idea before using this brute-force tool.

1. in an empty method list open a Script method.
2. Click the "Pre-batch script..." button and add the following lines:
//--------------------------
const indArr = [] ;
for ( i = 0 ; i < app.itemCount - 1 ; i++ ) {
j = i + 1
if ( app.getItem(i).name == app.getItem(j).name ) {
x = indArr.push( i, j ) ;
}
}
//--------------------------
3. Click the "Close and apply script" button (lower right on pre-batch window).
4. In the "main" window add the following lines and change the first three lines to suite your needs (be careful to leave the double-backslashes and, if you add additional subdirectories to the variable "baseDir", you'll need to add double-backslashes to suit. Variable "drive" is of course the drive where your files reside. "baseDir" is where you want your new directory of file-pairs to go, and "addDir" is the new directory name.
//--------------------------
drive = "D:" ;
baseDir = "\\FORUM\\" ;
addDir = "toWork\\" ;

myPath = drive + baseDir + addDir ;

if ( indArr.includes( index ) ) {
item.newPath = myPath ;
}
//--------------------------

5. Add the files in your directory and execute. All file pairs will be moved to your new directory.
6. Delete whatever you don't want and move the remaining files wherever you need them.

Best,
DF
Reply to #4:
OK. I'll get my head around that and give it a go. Thanks for the quick response!
Reply to #5:

Actually, David, I just realized your way would be simpler and easier. Leave the pre-batch script as-is (as-was?) and replace the main script with this:

if ( indArr.includes( index ) ) {
return item.name + " - Pairs" ;
}


That will give you what you asked for: each of the file pairs names will then end in " - Pairs.*".
[EDIT] Just make sure that the "Apply to:" box at the bottom of the script method is set to "Name". [END EDIT]

Best,
DF
Reply to #6:

You know that totally bogus -- but very fun -- story about the "NASA space pen" and the USSR cosmonaut's pencil? ... ...

Anyway, DF's approach will work. Good job DF, and you worked faster too. :D

There's a few caveats with that code:
1) Aren's "Pair renaming" must be turned off due to a bug in Aren 4.21.
2) Files must be listed in Aren in a very specific order.
3) No stray file types can exist in the folder or they might get affected too.
4) If there is a case mismatch in the files -- EG "Apple.heic" and "apple.mov" -- The script may not work as desired (depending on your particulars).

My approach does not depend on order, nor risk stray files. It's easily tuned to rename (or move) just the *.MOV file.


1) Create a new script method ( https://www.advancedrenamer.com/user_guide/v4/method_script ).

2) Paste this next code in the "Pre batch script" and apply it:

//-------------------------------------------------------
// Pre batch script
//-------------------------------------------------------
/*--- WARNING!
"Pair renaming" must be turned off as it completely lies to item processing here.
*/
const nameMap = {};
const masterExtensions = ["HEIC"]; // These must be uppercase
const sacrificeExtensions = ["MOV"]; // These must be uppercase
function standardizeExtension (sFileExtension) {
// Aren includes the leading period. Strip it. And make uppercase so .include always works.
return (sFileExtension.substr (1) ).toUpperCase ();
}

//-- Identify paired files but only of the specified types.
for (let J = 0, L = app.itemCount; J < L; J++) {
let item = app.getItem (J);
let fExt = standardizeExtension (item.newExt);

if (masterExtensions.includes (fExt) ){
(nameMap[item.name] ??= {} ).hasMaster = true; // Logical nullish assignment supported in Aren!
}
if (sacrificeExtensions.includes (fExt) ){
(nameMap[item.name] ??= {} ).hasSacrifice = true;
}
}
//-------------------------------------------------------

3) Then paste the following code in the "function(index, item)" block and apply it.

//-------------------------------------------------------
// "function( index, item)" script
//-------------------------------------------------------
if (nameMap[item.name]?.hasMaster && nameMap[item.name]?.hasSacrifice) {
// Will be true for both file types
return item.name + " - Pairs";
}
//-------------------------------------------------------

4) **** BE SURE THAT AREN'S "Pair renaming" IS TURNED OFF (UNCHECKED) ****


This will rename your pairs as specified. It's easy to add additional extensions, or just rename the "sacrifice" files, etc., with minor tweaks.

Regards,
Randy
Reply to #7:

... and that's why I advised to wait for your solution. :)

I, as per my usual MO, just did the first thing that popped into my head, because like a pencil in space, it's "good enough"!

Good job my friend. And I didn't know about the pair bug, I just always keep it off so it worked for me on a limited test set.

The file order thing is interesting, though. I have that setting about reordering files when dragged turned off, so mine always go in in the order they are in in Directory Opus, which for me is always filename order. Good point.

Keep crankin', buddy!
DF
Reply to #8:
Thank you. Both of you.
I've got time this weekend and I'll see what I can do!

UPDATE: Gave it a go. Worked beautifully! Thanks!