* Bulk rename of Media Records etc in my project

Questions regarding use of any Version of Family Historian. Please ensure you have set your Version of Family Historian in your Profile. If your question fits in one of these subject-specific sub-forums, please ask it there.
Post Reply
avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Bulk rename of Media Records etc in my project

Post by rocksrock » 30 Oct 2015 19:04

1.
Is there any way of bulk renaming a group of Media records, Source Records etc. inside the project. I can do the simple renames in Windows Explorer for the individual image names before they are loaded (eg use Bulk Rename Tool) or after they are loaded (if I then link the image to newly named media record) but how do I do it inside FH.

2 In Windows Explorer using Bulk Rename Ultility how would I change an image named

Marriage Alexander SMITH & Mary JONES 1999 Anytown (FreeBMD Snip).JPG

to be named

Marriage 1999 Alexander SMITH & Mary JONES (FreeBMD Snip).JPG

I know what I wan to tell it to do, but can't work out how to tell it to do it! There's obviously some expression to build. I can tell it to deleter individual symbols like - or + or words but can't figure to say
"Take those 4 numbers and the trailing space from near the end and pop them in after Marriage. Then go to those brackets and delete from one place left of the left bracket back to the next preceeding space"

:?

Any ideas anyone?

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 30 Oct 2015 20:35

OK, in reverse order:

2.
I assume you mean the Bulk Rename Utility at http://www.bulkrenameutility.co.uk/.
You will need to use the RegEx (1) section for Regular Expressions, which is explained in 3.8 Regular Expressions on page 30 of the PDF Manual.

For your specific example for Marriage files:
Match: ^Marriage (.+) (\d\d\d\d) .+ \((.+)\)$
Replace: Marriage \2 \1 (\3)

The Match means:
^Marriage = match leading 'Marriage '
(.+) = capture multiple chars ending with a space
(\d\d\d\d) = capture four digits ending with a space
.+ = match any chars ending with a space
\((.+)\)$ = capture trailing text within ( parentheses )

The Replace means:
Marriage = use text 'Marriage '
\2 = use 2nd capture of digits and a space
\1 = use 1st capture multiple chars and a space
(\3) = use 3rd capture within parentheses

If you have filenames starting with other than 'Marriage' that need similar treatment then let us know.

1.
Bulk rename of records is achieved with the Search and Replace Plugin, which has a similar LUA Pattern Mode.
I advise that you use File > Backup/Restore > Small Backup before using Plugin just in case!
After using Plugin you can also use Edit > Undo Plugin Changes before closing FH.

If they are already linked, then the renamed files from above will need a similar rename in the File field of Media records.
So having selected LUA Pattern Mode the expressions will be similar to above but using % instead of \:
Search: \Marriage (.+) (%d%d%d%d) .+ %((.+)%)%.
Replace: \Marriage %2 %1 (%3).
Notice that they start with \ because Media folders can precede the filename, and end with a dot extension separator.
The leading folder names and trailing file extension will remain unaltered.

Now on the Extra Filters tab, untick every option except Multimedia Format & Linked File fields, then click Search & Replace, but Skip each item to check the correct changes are being made, and finally click Cancel.
When satisfied the bulk change is what you want then click Search & Replace and use Replace and perhaps untick Confirm every item found.
When the Plugin is closed a Result Set will list all changes made.

To bulk rename record titles uses a similar technique, but on the Extra Filters tab, untick every option except Record Names/Titles and choose the record type from the drop-list to the right.

The Help & Advice button offers tips and examples, and cross-reference to plugins:understanding_lua_patterns|> Understanding Lua Patterns.

If you are likely to need to repeat those bulk renames then the Plugin has a Manage Presets option to preserve any number of search & replace settings.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 30 Oct 2015 23:10

Mike, this is magnificent and you are on holiday too! - please take an extra day!

2. That's right, that is the utility I meant.

Now I begin to see a little light. I had looked at the Help abut it looked double Dutch. But looking at what you have done it looks to me that you: divided my original title into four segments; then wrote the code to describe each segment as it is now; and then said OK, take that lot and do this to it so it is re-arranged as required, and then kindly ignore the bits the lady doesn't want - roughly?

I think I can get my head round that and can write the same thing for one or two others. When I have done that perhaps you would check them for me (It'll be a few days - life is mad this week and next!)

1. For re-naming the bulk records, I think I will make a copy of a small segment of my file and then try playing with that using the plug-in to rename differnt types of records and see how I do.

A lot of them do already have linked images so I can do that the way you suggest too.
I'm going to do baby steps till I get the hang of it - I hadn't heard of LUA till I started reading this forum and about plug-ins, it's a newand interesting world but rather far off from my usual.... watch this space.

And THANK YOU!

User avatar
johnmorrisoniom
Megastar
Posts: 882
Joined: 18 Dec 2008 07:40
Family Historian: V7
Location: Isle of Man

Re: Bulk rename of Media Records etc in my project

Post by johnmorrisoniom » 31 Oct 2015 07:08

On a similar note, is it possible to bulk rename media files to match it's title in FH?

John

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 31 Oct 2015 14:50

John, anything is 'possible'!!!

If the Media Title has no logical textual relationship to the File Name then you cannot use the techniques described here.

Furthermore, a File Name is not allowed to contain any of \ / : * ? " < > | so if those occur in the Media Title then they must be excluded. Also there is nothing to stop several Media records all having the same Title, but all File Names within one folder must be different!

A custom Plugin could perform the task quite easily by looping through all Media records, and for each record would rename the linked Media File Name itself, and the File field within the record, both to match the Title field, excluding the banned characters, and report if there are any File Name conflicts.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 05 Nov 2015 14:52

Hello Mike,

I've been trying the RegEx example above, fine so far.

Now I am trying to do the same thing on similar marriage image file names, except that the part in the trailing brackets is of the form (IMG_1234)

I've tried adapting your example by inserting (\d\d\d\d) into the match file segment \((.+)\)$ after the \((.+) and before the \)$ so \((.+)(\d\d\d\d))\)$ nothing happens. Also no go if I add a space between the 2 halves of the string thus .+) (\d

Please what am I missing?

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 05 Nov 2015 15:21

You should not need to change anything because \((.+)\)$ will match any trailing text in brackets.
The details are:
\( matches opening bracket
.+ matches any series of characters, e.g. IMG_1234
\) matches closing bracket
$ matches end of filename
The ( ) around .+ captures that text for insertion into the replacement name.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 05 Nov 2015 15:49

Ah Ha. I had assumed that because in one place it needed \d\d\d\d to register a group of numbers, that it would need them everywhere!

Thank you!

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 05 Nov 2015 17:08

Next complication:

DEATH 1899 SMITH (Gill) Mary Margaret (BD Scan).jpg

I've tried representing it like this:
Match: ^Death (\d\d\d\d) (.+) ((.+)) (.+) (.+) \((.+)\)$

Replace: Death \1 \4 \3 \2 (\5)

but no go.

Then I tried representing the surname as ([A-Z]*), the maiden surname in brackets as ([A-Z)[a-z]*) and the Given name as ([A-Z][a-z]*) second given name as ([A-Z][a-z]*) and the trailing brackets as before to give

Match: ^Death (\d\d\d\d) ([A-Z]*) ([A-Z)[a-z]*) ([A-Z][a-z]*) ([A-Z][a-z]*) \((.+)\)$
Replace: : no go.

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 05 Nov 2015 17:09

Sorry, the last bit should say Death \1 \4 \5 \3 \2 (\5)

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 05 Nov 2015 18:34

Oh Dear! Bear of small brain episode.

Replace: Death \1 \4 \5 \3 \2 (\6) is whta I think I need?

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 05 Nov 2015 18:45

Two important things:
If the filename starts DEATH then the match must start ^DEATH not ^Death
To match the bracketed maiden name needs \(([A-Z][a-z]*)\) where \( matches ( and \) matches ) and the \ escape character says treat next char literally to distinguish from the 'magic' ( ) that capture text.

Which replacement captures you need is up to you, but the numbers represent the ordinal position of the capturing ( ) chars.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 05 Nov 2015 18:59

Mike,

You mention an escape character \

We have used \( and \) to specify the opening and closing brackets around the text I am trying to capture. So the escape character you mention is this \ just before the ( and just after the ) yes??

I suppose that it can be applied to any character if necessary, or are there exceptions?

Thank you!

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 05 Nov 2015 20:03

Nearly right.

The escape character is this \ just before the ( and just before the )
i.e. the escape \ always comes before the character it escapes.

You may have noticed that certain 'magic' characters have a special meaning,
e.g. ^ $ ( ) [ ] . * + etc...
So to match such characters literally they need the escape \ before them.
i.e. to match ^ needs \^ and to match * needs \*

It cannot be applied to all characters because some have special meanings.
e.g. literal d matches d but \d is shorthand for digits [0-9]
and literal u matches u but \u is shorthand for uppercase [A-Z]
and there are many others but I think they are all letters.

The Bulk Rename Utility uses the Perl variant of Regular Expressions so Google Perl Regular Expresions for plenty of specifications and tutorials.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 05 Nov 2015 20:28

Thank you and I'll be sure to follow that source!

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 12 Nov 2015 22:37

Well a week's silence means I've been getting along quite happily. I have managed to rename all the individual image files to my new preference. I've also relinked the images to the appropriate records and made a few amendment to the latter where appropriate (doing that bit manually)

Now i would like to retitle the Media Records using the plug-in.

Birth Jane Jemima Joanna SMITH 1999 (FreeBMD_Snip)
to
Birth 1999 Jane Jemima Joanna SMITH (FreeBMD_Snip)

So:

Match: Birth (.+) (%d%d%d%d) %((.+)%0%.
Replace: Birth %2 %1 (%3).

I've got the LUA pattern mode selected;
in Distinctive Fields I have Record Names/Titles selected;
In the Media Records window I've highlighted only those records whose names I wish to change;
On extra Filters I've selected only the Multimedia Format & Linked files

But on a "Search ONLY" no records are selected. :(

What have I omitted or done wrong?

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 12 Nov 2015 23:15

The main reason there is no match is that the Match should end with %((.+)%)
i.e. the trailing %. demands that the last char must be a literal fullstop which is not the case.

So also the Replace should not end with a fullstop, because there are no fullstop in your titles.

To be more pedantic the Match should start with ^ and end with $ that are the start of text and end of text anchors respectively.

Against Record Names/Titles select Multimedia from the droplist to focus on those records.

Do not select Multimedia Format & Linked File fields because you are not trying to change them.

It is pointless selecting records in Multimedia Window as that has no effect in Plugin.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 12 Nov 2015 23:20

:oops: :oops: :oops:

I had forgotten that I was trying to change the titles not the file name - hence the full stops etc!

Is it always the case that any match using LUA or the Bulk Rename Utility will always want ^ to start with and $ for trailing text - I suppose so? Crawls off to bed resolving to do better tomorrow!

Thank you.

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 12 Nov 2015 23:55

No, it is not always necessary to use ^ and $ because you may not want to anchor the pattern match to the ends of the text.

e.g. If you want to change just the filename part of a Linked File path, then it would start with \ and end with %. to match the folder \ separator and extension . separator and allow any leading folder name and trailing extension.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 13 Nov 2015 10:46

Done it! :D

Thank you! :lol: :D

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 10 Dec 2015 14:33

Mike, I am now trying to rename some source records, including moving the date and changing the title name of the records, thus

NAME-BIRTH Benjamin SMITH 1910 to become Birth 1910 Benjamin SMITH

I am omitting initial \ cos I'm not changing a file name; likewise omitting terminal fullstop for same reason

Search NAME-BIRTH .+ .+ %d%d%d%d
Replace Birth %3 %1 %2

Then I have selected Search Scope to Source Records and
in Distinctive Fields have selected Record Names/Titles to Source Title

Running the plug-in with this is finding nothing and there are 300+ records to find! I'm sure it is something so obvious I ought to see it but I have tried several variants all to no avail. What have I missed this time?

User avatar
tatewise
Megastar
Posts: 27079
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Bulk rename of Media Records etc in my project

Post by tatewise » 10 Dec 2015 14:49

Good try but Search needs to be NAME%-BIRTH (.+) (.+) (%d%d%d%d)

The hyphen (-) is a 'magic' character such as ^ $ % . + * ? ( ) [ ] and to switch off its 'magic' must be prefixed with % so it literally matches a hyphen, as explained in plugins:understanding_lua_patterns|> Understanding Lua Patterns.

The three text components must be 'captured' with (parentheses) to provide the text for %1 %2 %3.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
rocksrock
Platinum
Posts: 48
Joined: 06 Sep 2011 11:39
Family Historian: V6

Re: Bulk rename of Media Records etc in my project

Post by rocksrock » 10 Dec 2015 15:25

Doh! Of course, that's why in our earlier examples we had some .+ with brackets and others without! and I had forgotten about those magic characters too :oops:

Thank you very much, once again! :D

Post Reply