Moving part of the title of many files; adding separator
Hi,
I'm new to Advanced Renamer, and am therefore completely clueless. My apologies for my incompetence. I'm just trying to move part of the title of many files and add a separator.
Here is a real example of a title: 20230520T161921--reghem-albert__fusilles-aisne_reghem-albert_saintquentin-sentinelle-8avril1944.org
That is: identifier--surname-first name__several keywords.org. As you can see, the number of keywords varies, and they may include numbers; the identifier is based on the date and time (ymdThms).
What I would like to obtain: --reghem-albert@@20230520T161921__fusilles-saintquentin-sentinelle-8avril1944.org
So with a new separator (@@) between name-forname and identifier.
Here's what I tried (and how I failed):
1. I first tried the ‘move’ method, which seemed the most appropriate to me. But I didn't understand the logic behind it:
- ‘Move from’ where (1st element, therefore 1) ?
- ‘Move count’ what?
- ‘Move to’ where (2nd position, therefore 2)?
2. So, test using the ‘Replace’ method (I added @@ manually before the identifier, thinking I would save time: well done…).
I don't know how to insert a hyperlink...
<a href="https://ibb.co/mCK3Sp95"><img src="https://i.ibb.co/mCK3Sp95/Capture.png" alt="Capture" border="0"></a>
[url=https://ibb.co/mCK3Sp95][img]https://i.ibb.co/mCK3Sp95/Capture.png[/img][/url]
Thank a lot for your help!
Fred
I'm new to Advanced Renamer, and am therefore completely clueless. My apologies for my incompetence. I'm just trying to move part of the title of many files and add a separator.
Here is a real example of a title: 20230520T161921--reghem-albert__fusilles-aisne_reghem-albert_saintquentin-sentinelle-8avril1944.org
That is: identifier--surname-first name__several keywords.org. As you can see, the number of keywords varies, and they may include numbers; the identifier is based on the date and time (ymdThms).
What I would like to obtain: --reghem-albert@@20230520T161921__fusilles-saintquentin-sentinelle-8avril1944.org
So with a new separator (@@) between name-forname and identifier.
Here's what I tried (and how I failed):
1. I first tried the ‘move’ method, which seemed the most appropriate to me. But I didn't understand the logic behind it:
- ‘Move from’ where (1st element, therefore 1) ?
- ‘Move count’ what?
- ‘Move to’ where (2nd position, therefore 2)?
2. So, test using the ‘Replace’ method (I added @@ manually before the identifier, thinking I would save time: well done…).
I don't know how to insert a hyperlink...
<a href="https://ibb.co/mCK3Sp95"><img src="https://i.ibb.co/mCK3Sp95/Capture.png" alt="Capture" border="0"></a>
[url=https://ibb.co/mCK3Sp95][img]https://i.ibb.co/mCK3Sp95/Capture.png[/img][/url]
Thank a lot for your help!
Fred
Reply to #1:
Hi LeFred, welcome,
First, compliments on your excellent file structure; it's easy to reconfigure filenames when the parts are delimited in such a smart manner. So congratulations on that!
Second, I can't see your examples. I can tell you how to use google drive to insert links if you want, but I'm sure someone else here can cover ibb.co. Guys?
Now to your question: First, the short answer: A replace method with:
Replace:
([^-]+)--([^_]+)__
Replace with:
--$2@@$1__
Occurrence: All or 1st
Use regular expressions: CHECKED
Apply to: Name
The rest may be [TL;DR] if you just want to get the job done. From here on is [mostly] explanation of regex code.
Here's a breakdown of the first regular expression:
([^-]+) -> (Starting from the first character) capture everything up to the first dash. The parentheses denote a "capture group". This will be "capture group one"; aka $1 in the Replace with: string.
-- -> Move through (i.e., eliminate) two consecutive dashes
([^_]+) -> Capture everything up to the next underscore.
__ -> Eliminate two underscores
If you enter the Replace: string without the Replace with: string and look at the New Filename column, you'll see your filename without the first two fields and delimiters. The Replace with: string just puts stuff you've captured back into the filename and adds whatever you want.
-- -> (From file start) Insert two dashes
$2 -> Insert "capture group" two (surname-first name)
@@ ->Insert two ampersands
$1 -> Insert capture group one (identifier)
__ -> Insert two underscores
This all goes in before the rest of the filename, because the remainder wasn't mentioned in the Replace: portion.
Ok, I have to point out that in your example new filename there was part of the "keywords" that was missing from the original filename. I think leaving out the word "aisne" might have been a mistake, but the other difference was elimination of the "surname-first name" repeated in the keywords part. If you want to do that here's the modified regular expression:
Replace:
([^-]+)--([^_]+)__(.*)_\2(.*)
Replace with:
--$2@@$1__$3$4
Everything is the same up to the double-underscore; we've added something to capture the rest of the filename into two more capture groups (parens) plus a "backreference" to capture group two (\2). I should probably say that "$" or "\" (backslash) can stand for capture group in the Replace with string; but if you want to tell the regex engine to look for a previously-defined capture group, or backreference, while looking through the original string, you have to use the backslash. Oh, the last underscore just deletes one of the underscores surrounding \2 so you don't have another double-underscore.
Screenshot: https://drive.google.com/file/d/1wzmeYm7_nLD1Jk03XxDQXe8WpfN RFWdH/view?usp=sharing
Let me know how that works for you, and any questions.
Best,
DF
Hi LeFred, welcome,
First, compliments on your excellent file structure; it's easy to reconfigure filenames when the parts are delimited in such a smart manner. So congratulations on that!
Second, I can't see your examples. I can tell you how to use google drive to insert links if you want, but I'm sure someone else here can cover ibb.co. Guys?
Now to your question: First, the short answer: A replace method with:
Replace:
([^-]+)--([^_]+)__
Replace with:
--$2@@$1__
Occurrence: All or 1st
Use regular expressions: CHECKED
Apply to: Name
The rest may be [TL;DR] if you just want to get the job done. From here on is [mostly] explanation of regex code.
Here's a breakdown of the first regular expression:
([^-]+) -> (Starting from the first character) capture everything up to the first dash. The parentheses denote a "capture group". This will be "capture group one"; aka $1 in the Replace with: string.
-- -> Move through (i.e., eliminate) two consecutive dashes
([^_]+) -> Capture everything up to the next underscore.
__ -> Eliminate two underscores
If you enter the Replace: string without the Replace with: string and look at the New Filename column, you'll see your filename without the first two fields and delimiters. The Replace with: string just puts stuff you've captured back into the filename and adds whatever you want.
-- -> (From file start) Insert two dashes
$2 -> Insert "capture group" two (surname-first name)
@@ ->Insert two ampersands
$1 -> Insert capture group one (identifier)
__ -> Insert two underscores
This all goes in before the rest of the filename, because the remainder wasn't mentioned in the Replace: portion.
Ok, I have to point out that in your example new filename there was part of the "keywords" that was missing from the original filename. I think leaving out the word "aisne" might have been a mistake, but the other difference was elimination of the "surname-first name" repeated in the keywords part. If you want to do that here's the modified regular expression:
Replace:
([^-]+)--([^_]+)__(.*)_\2(.*)
Replace with:
--$2@@$1__$3$4
Everything is the same up to the double-underscore; we've added something to capture the rest of the filename into two more capture groups (parens) plus a "backreference" to capture group two (\2). I should probably say that "$" or "\" (backslash) can stand for capture group in the Replace with string; but if you want to tell the regex engine to look for a previously-defined capture group, or backreference, while looking through the original string, you have to use the backslash. Oh, the last underscore just deletes one of the underscores surrounding \2 so you don't have another double-underscore.
Screenshot: https://drive.google.com/file/d/1wzmeYm7_nLD1Jk03XxDQXe8WpfN RFWdH/view?usp=sharing
Let me know how that works for you, and any questions.
Best,
DF