* Renaming Media Files
Renaming Media Files
How can I rename files already linked to records?
I like the way AS names media files as it copies them into FH but I need to go back and tidy up my existing media filenames. I've searched but can't find the procedure for doing this within FH.
I like the way AS names media files as it copies them into FH but I need to go back and tidy up my existing media filenames. I've searched but can't find the procedure for doing this within FH.
John Wright ... researching the Hume & Wright family histories
- trevorrix
- Famous
- Posts: 228
- Joined: 17 Nov 2002 20:27
- Family Historian: V7
- Location: Suffolk, England
Re: Renaming Media Files
If you wish to rename a media file, in FH find the media item in Media > View All Media, then double click that media item thumbnail. At the bottom of the Media Record tab you will see the existing filename together with the Location of that file. Click the Location link which will automatically select the file for you, which you can right click and Rename. After you have renamed the file, change the last element of Linked File: in the Multimedia Object property box (which should be in view to the right of FH) to match the new filename.
Trevor Rix
- Jane
- Site Admin
- Posts: 8440
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Renaming Media Files
I wrote myself a plugin which renames the Files based on the titles of the Media records, it's not at plugin store quality, but you might be able to use it as a base. It prefixes the names with the Media Record Number, but it would be easy to change.
- Attachments
-
Rename Selected Media Files.fh_lua- (1.37 KiB) Downloaded 267 times
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
- johnmorrisoniom
- Megastar
- Posts: 882
- Joined: 18 Dec 2008 07:40
- Family Historian: V7
- Location: Isle of Man
Re: Renaming Media Files
Jane, knowing little about plugins, but using them a lot, How would I modify your plugin to just rename files to be the same as the internal title (No record ID prefix)
My naming conventions have changed over the years, and as such I have several 1000 records to catch up on.
My naming conventions have changed over the years, and as such I have several 1000 records to catch up on.
Re: Renaming Media Files
Thanks Trevor, your method worked fine. I have a few hundred poorly named media files so I'll try Jane's plugin.
John Wright ... researching the Hume & Wright family histories
Re: Renaming Media Files
Thanks, Jane. I've checked out your plugin and the concept would work brilliantly. I'm tempted to indulge in the experiment of modifying the plugin, which I'm sure in the right hands would be elementary. In my case, however - a digression I must resist. If you find the time, johnmorrisoniom's request to replace the existing filename with the media title would be ideal!
A less efficient, albeit more intuitive solution for a future version of FH would be a "Rename media file" option in the media window context menu.
Thanks for the prompt reply.
J.
A less efficient, albeit more intuitive solution for a future version of FH would be a "Rename media file" option in the media window context menu.
Thanks for the prompt reply.
J.
John Wright ... researching the Hume & Wright family histories
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Renaming Media Files
OK guys, here is how to modify the Plugin.
In Tools > Plugins make sure More>> is clicked so it says <<Less and the button bar on right is revealed.
Select the Plugin name and click Edit button to open the Plugin Editor.
About line 25 you will find the script line that composes the new file name from the Title:-
newfile = 'O'..id..'_'..string.gsub(fhGetItemText(ptr,'~.TITL'),'[_%W]','_')..'.'..ext
Replace it with:-
newfile = string.gsub(fhGetItemText(ptr,'~.TITL'),'[_%W]','_')..'.'..ext
i.e. delete the 'O'..id..'_'.. part which is prefixing the letter 'O' and RecordId from two lines above.
The remainder of that script line replaces every underscore & non-alphanumeric character '[_%W]' with an underscore '_' and suffixes the file extension. That is done to avoid illegal filename characters.
Use File > Save and the job is done.
Beware that if by any chance you have multiple Media records with the same Title then there will be a filename clash, and similarly if any other file in the same Media folder has the same filename. That is why the Plugin added the RecordId to ensure the filename is unique.
In Tools > Plugins make sure More>> is clicked so it says <<Less and the button bar on right is revealed.
Select the Plugin name and click Edit button to open the Plugin Editor.
About line 25 you will find the script line that composes the new file name from the Title:-
newfile = 'O'..id..'_'..string.gsub(fhGetItemText(ptr,'~.TITL'),'[_%W]','_')..'.'..ext
Replace it with:-
newfile = string.gsub(fhGetItemText(ptr,'~.TITL'),'[_%W]','_')..'.'..ext
i.e. delete the 'O'..id..'_'.. part which is prefixing the letter 'O' and RecordId from two lines above.
The remainder of that script line replaces every underscore & non-alphanumeric character '[_%W]' with an underscore '_' and suffixes the file extension. That is done to avoid illegal filename characters.
Use File > Save and the job is done.
Beware that if by any chance you have multiple Media records with the same Title then there will be a filename clash, and similarly if any other file in the same Media folder has the same filename. That is why the Plugin added the RecordId to ensure the filename is unique.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Renaming Media Files
Brilliant. Works a charm.
Thanks Mike.
Thanks Mike.
John Wright ... researching the Hume & Wright family histories
- johnmorrisoniom
- Megastar
- Posts: 882
- Joined: 18 Dec 2008 07:40
- Family Historian: V7
- Location: Isle of Man
Re: Renaming Media Files
Just got around to trying the modified plugin (No ID) and have noticed that the rename also replaces space and () with the _ character (Which windows does allow in filenames). Is there a way to stop this happening?
TIA John
TIA John
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Renaming Media Files
Yes, the bit to change is the '[_%W]' in the gsub(...) function.
That identifies the characters to substitute as documented in plugins:understanding_lua_patterns|> Understanding Lua Patterns.
The '[set]' identifies the set of characters to be changed.
_ underscore represents itself (and is not strictly needed at all).
%W is the upper-case version of %w or all alphanumeric characters, so is all non-alphanumeric characters.
It is probably easiest to use '[^set]' that identifies the complement of the set of characters to be changed.
In other words, it lists the characters to retain unchanged, and all the others must be changed.
%w represents all alphanumeric characters to be retained
%( represents open parenthesis (the leading % is needed to inhibit its 'magic' meaning).
%) represents close parenthesis similarly.
space represents itself.
So the final definition is '[^%w%(%) ]' to replace '[_%W]'
Easy when you have been doing it as long as I have
That identifies the characters to substitute as documented in plugins:understanding_lua_patterns|> Understanding Lua Patterns.
The '[set]' identifies the set of characters to be changed.
_ underscore represents itself (and is not strictly needed at all).
%W is the upper-case version of %w or all alphanumeric characters, so is all non-alphanumeric characters.
It is probably easiest to use '[^set]' that identifies the complement of the set of characters to be changed.
In other words, it lists the characters to retain unchanged, and all the others must be changed.
%w represents all alphanumeric characters to be retained
%( represents open parenthesis (the leading % is needed to inhibit its 'magic' meaning).
%) represents close parenthesis similarly.
space represents itself.
So the final definition is '[^%w%(%) ]' to replace '[_%W]'
Easy when you have been doing it as long as I have
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- johnmorrisoniom
- Megastar
- Posts: 882
- Joined: 18 Dec 2008 07:40
- Family Historian: V7
- Location: Isle of Man
Re: Renaming Media Files
Brilliant,
Thanks Mike, i actually modified it slightly to include - to be left so used [^%w%(%)%- ]
Now a step further.
My media titles all have the media type keyword as the first word
i.e.
Marriage 1925 Douglas (St Georges) - (Page 240)
Baptism 1877 Douglas (St Matthews) - (Page 188)
Census 1901 IOM Douglas - RG13 piece 5305 folio 013 page 18
is it possible for the rename process to remove the 1st word from the string, so that the media titles stay the same but the filenames would become
1925 Douglas (St Georges) - (Page 240)
1877 Douglas (St Matthews) - (Page 188)
1901 IOM Douglas - RG13 piece 5305 folio 013 page 18
Regards
John
Thanks Mike, i actually modified it slightly to include - to be left so used [^%w%(%)%- ]
Now a step further.
My media titles all have the media type keyword as the first word
i.e.
Marriage 1925 Douglas (St Georges) - (Page 240)
Baptism 1877 Douglas (St Matthews) - (Page 188)
Census 1901 IOM Douglas - RG13 piece 5305 folio 013 page 18
is it possible for the rename process to remove the 1st word from the string, so that the media titles stay the same but the filenames would become
1925 Douglas (St Georges) - (Page 240)
1877 Douglas (St Matthews) - (Page 188)
1901 IOM Douglas - RG13 piece 5305 folio 013 page 18
Regards
John
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Renaming Media Files
Yes, easy peasy!
Insert this extra line below the one we have been editing:
newfile = string.gsub(newfile,'^%a+ (.*)','%1')
The 1st quoted string says:
^ anchor to start of filename
%a any letter
+ repeated one or more times i.e. detect the first alphabetic word ending in a space
until a space character
( start capture ~ this is the magic use of ( and )
.* all other text through to end of filename
) end capture
The 2nd quoted string says:
%1 substitute everything with the 1st captured text
What is more difficult is removing those leading keywords from the actual filenames within the Media folder?
Insert this extra line below the one we have been editing:
newfile = string.gsub(newfile,'^%a+ (.*)','%1')
The 1st quoted string says:
^ anchor to start of filename
%a any letter
+ repeated one or more times i.e. detect the first alphabetic word ending in a space
until a space character
( start capture ~ this is the magic use of ( and )
.* all other text through to end of filename
) end capture
The 2nd quoted string says:
%1 substitute everything with the 1st captured text
What is more difficult is removing those leading keywords from the actual filenames within the Media folder?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- johnmorrisoniom
- Megastar
- Posts: 882
- Joined: 18 Dec 2008 07:40
- Family Historian: V7
- Location: Isle of Man
Re: Renaming Media Files
Thanks Mike,
That works exactly as I want it to, I just have to watch out for filenames that start with the year (Ie already tweaked), But I have re-arranged the media tab columns to see that.
Thanks for your help
John
That works exactly as I want it to, I just have to watch out for filenames that start with the year (Ie already tweaked), But I have re-arranged the media tab columns to see that.
Thanks for your help
John
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Renaming Media Files
That extra Plugin line should have no impact of filenames that start with year, because it is only detecting leading alpha and will ignore leading numbers.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- PeterR
- Megastar
- Posts: 1129
- Joined: 10 Jul 2006 16:55
- Family Historian: V7
- Location: Northumberland, UK
Re: Renaming Media Files
FileMenu Tools includes an Advanced Renamer… that can use Regular Expressions.What is more difficult is removing those leading keywords from the actual filenames within the Media folder?
Peter Richmond (researching Richmond, Bulman, Martin, Driscoll, Baxter, Hall, Dales, Tyrer)
Re: Renaming Media Files
Hi Jane:
I recently gave titles to several hundred media files that just had numbers for the file name and title.
I'd love to be able to change most of them using your plugin. I'm getting an error when I try to run it (tried with just a few files to test). Maybe you have an idea on what is wrong? Here is the error:

Thanks,
Matthew
- PeterR
- Megastar
- Posts: 1129
- Joined: 10 Jul 2006 16:55
- Family Historian: V7
- Location: Northumberland, UK
Re: Renaming Media Files
Looks like a filename has no extension?
Peter Richmond (researching Richmond, Bulman, Martin, Driscoll, Baxter, Hall, Dales, Tyrer)
- Jane
- Site Admin
- Posts: 8440
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Renaming Media Files
It will need some changes to work on FH7. As the tag for Files is different on FH7.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Renaming Media Files
See the posting Zooming Media images (20335) that has two updated versions of the plugin.
Also, the thread re naming source/media files (17412) has another updated variant.
It depends on exactly what you want the renaming to do.
Also, the thread re naming source/media files (17412) has another updated variant.
It depends on exactly what you want the renaming to do.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: Renaming Media Files
Perfect! Thank you Mike, Jane and Peter.
I used the one with no id from 2022 (https://www.fhug.org.uk/forum/viewtopic ... 35#p122146) and it worked great. That saved me hours of tedious renaming one file at a time. FH 7 and you all are great!!
Matthew
I used the one with no id from 2022 (https://www.fhug.org.uk/forum/viewtopic ... 35#p122146) and it worked great. That saved me hours of tedious renaming one file at a time. FH 7 and you all are great!!
Matthew