Hard to find solution for easiest problem

Advanced Renamer forum
#1 : 21/04-24 21:10
Arthur
Arthur
Posts: 3
I have a directory of subfolders with a path (for example)
"D:\TShirt\Catalog BT\BG_Music\btdBG_Foreign Music\1"

In folder 1 there are 6 files which names are:
1 copy.png
1.png
2.png
3.png
4.png
sample.png

How do I rename all of them with just one enabled method?
I need <DirName:2><DirName:1> for file 1.png, <DirName:2><DirName:1>_<Name> for files from 2.png to sample.png except 1 copy.png (it should stay without renaming)

List replace method didn't work in my case:
I write
^1 -> <DirName:2><DirName:1>
^2 -> <DirName:2><DirName:1>_2
^3 -> <DirName:2><DirName:1>_3
^4 -> <DirName:2><DirName:1>_4
^sample -> <DirName:2><DirName:1>_sample

But it works only for 1.png, result is btdBG_Foreign Music 1, the other files is _2. _3 etc

What am I doing wrong? I understand that the task is simple, but I can't solve it in any way. Please help. P.s. RegEx is enabled in the method


21/04-24 21:10
#2 : 22/04-24 00:30
Delta Foxtrot
Delta Foxtrot
Posts: 111
Reply to #1:

Hi Arthur,

Sometimes the easiest LOOKING problems... Well, you know.

You can't think of the LIST REPLACE method as just a series of REPLACE methods all strung together in one method. I've had mixed results, at bests, using List replace. It doesn't seem to handle tags consistently (for instance, in studying your problem I found that if I used <DirName:2> I got (usually) nothing, but if I used <DirName:-4>, for instance, I got (usually) the dirname slice I wanted. Go figure.

Anyway, I can do what you asked in two Replace methods or one script. Since you asked for a solution in one enabled method, here's the script (no Pre-batch):

const tPath = item.path;
const p = tPath.split("\\");
var pl = p.length;
var n = item.newBasename;
myPath = p[pl-4]+p[pl-3];

if (n.includes("copy")){
return n ;
} else if (n == "1"){
return myPath;
} else {
n = myPath + "_" + n ;
}

return n;

------------------------------------------------------------------------
If I might ask, why are you specifying only one enabled method? Is it because you use a method list with some methods disabled, then turn on methods and run it again (or something similar)?

Just curious.

Best from Texas,
DF

EDIT:
Oh yeah, here's the two replace methods, if you're interested (regex on):

replace: ^([2-9s])
with: <DirName:3><FolderName:2>_$1$2

replace: ^1$
with: <DirName:3><FolderName:2>

END EDIT


22/04-24 00:30 - edited 22/04-24 01:03
#3 : 22/04-24 11:22
Arthur
Arthur
Posts: 3
Reply to #2:
Wow, thank you very much, you helped me out a lot!
Yes, I use a list of methods at once to process 5-10 thousand images at a time.

And before your help, I had 7 replacement methods, I had to sort the list, turn on a method for replacing 1.png, rename, turn it off, sort, then for 2.png, and so on. I understood that this could be avoided, but I did not know how. Thank you very much.


22/04-24 11:22