Add folder name to filename, skip if already contain
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 - "?
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 - "?
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
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
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
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
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/1fmPwAYoy3FE0UmwyeFWKg0BD7TQ u6SMg/view?usp=drive_link
Miguel.
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/1fmPwAYoy3FE0UmwyeFWKg0BD7TQ u6SMg/view?usp=drive_link
Miguel.
Reply to #4:
Good morning(?) Miguel,
<stir> Wouldn't that fail if there was a hyphen in the original filename? :)
Best,
DF
Good morning(?) Miguel,
<stir> Wouldn't that fail if there was a hyphen in the original filename? :)
Best,
DF
Reply to #5:
Good night,
LOL.
You always thinking the worst scenario!!
YESSSS!!!
IT FAIL TOTALLY!!!
:((
Let´s hope there isn´t
Miguel.
Good night,
LOL.
You always thinking the worst scenario!!
YESSSS!!!
IT FAIL TOTALLY!!!
:((
Let´s hope there isn´t
Miguel.
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
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