Add folder name to filename, skip if already contain

Advanced Renamer forum
#1 : 14/11-24 09:53
copenhagen72
Posts: 1
I want to add folder name to filename, skip if already have.

Example:
FolderName/filename1.extnsn -> FolderName/FolderName - filename1.extnsn

Obvious way:
New name: <FolderName:1> - <Name>

But if I done it once and already have:
FolderName/FolderName - filename1.extnsn

then next time I will get:
FolderName/FolderName - FolderName - filename1.extnsn
with doubled folder name in filename.

How to avoid this, how to collapse all doubled, maby tripled "FolderName - FolderName..." to single "FolderName - "?
#2 : 14/11-24 12:04
Styb
Posts: 122
Reply to #1:
Hi, maybe I don't understand your question well, but if you're using version 4.x you can use the {If} function to avoid adding the folder name if it's already in the filename. As well as in the image:
https://ibb.co/TTJ46LV

edited: 15/11-24 08:44
#3 : 14/11-24 18:09
Delta Foxtrot
Posts: 357
Reply to #2:

Hi guys,

Just to stir the pot, there's another way to do that. I try to avoid the {if} if possible because I forget to check it when I'm changing expressions in my methods. So here's the way I'd do it without using {if}:

Start with your original New name method:

<Foldername:1> - <Name>

Add a Replace method:

Replace: "<Foldername:1> - <Foldername:1> - " (no quotes)
Replace with: "<Foldername:1> - " (no quotes)

OR- (using regular expressions)

Replace: "(<Foldername:1> - )\1"
(with the same Replace with: expression)

That's it. Be sure to set the Name collision rule to something appropriate if you might have multiple files with the same base name in a folder.

Best,
DF
#4 : 14/11-24 19:27
Miguel
Posts: 159
Reply to #1:
Hi,
Starting from Styb's solution.

Here we go! Let´s stir the pot.

New Name method: <FolderName:1> - <Name>
IF condition:
Field: Name ------> Contain
Pattern: - (hyphen)
Not matching: OK

New Collision Rule: Append image subsecond: _

https://drive.google.com/file/d/1fmPwAYoy3FE0Umw yeFWKg0BD7TQu6SMg/view?usp=drive_link

Miguel.



#5 : 14/11-24 19:32
Delta Foxtrot
Posts: 357
Reply to #4:

Good morning(?) Miguel,

<stir> Wouldn't that fail if there was a hyphen in the original filename? :)

Best,
DF
#6 : 14/11-24 19:50
Miguel
Posts: 159
Reply to #5:
Good night,

LOL.
You always thinking the worst scenario!!

YESSSS!!!
IT FAIL TOTALLY!!!

:((
Let´s hope there isn´t
Miguel.



edited: 14/11-24 20:18
#7 : 14/11-24 21:42
Delta Foxtrot
Posts: 357
Reply to #6:

You are correct, sir, my glass always seems to be half empty. Could be because I love wine, but probably because I so often have to go back and fix my mistakes, no matter how much I try to foresee said problems. Of course, that could be the wine too! :)

Another reason I try to avoid {if}. Also, the {if} conditional is case insensitive, so I have more control using an additional method instead.

Best,
DF