Page 1 of 1

Media File Names in queries

Posted: 31 May 2022 13:02
by Little.auk
I have my Media files split into sub-directories in the MEDIA folder.

I have a Multimedia query that uses the Expression %OBJE.FILE[1]% which returns the path and file name e.g. Media\BMD Records\05-Marriages\Parish Records\Marriage (PR) DOHERTY Thomas - BARLOW Ada J [FAM-088].jpg

Is there any Function \ Expression that will give me just the file name without the path?

Re: Media File Names in queries

Posted: 31 May 2022 13:17
by tatewise
The best I can think of is the =Section(...) function using the \ folder separator.
e.g.
=Section( %OBJE.FILE[1]%, 5, "\" ) should return Marriage (PR) DOHERTY Thomas - BARLOW Ada J [FAM-088].jpg for your example, but depends on there being 4 parent folders. Unfortunately there is no option for last section.

If there are only a few variations in the depth of parent folders then you could use =TextIf(...) to cope with that.
e.g.
=TextIf( Section( %OBJE.FILE[1]%, 5, "\" ) = "" , Section( %OBJE.FILE[1]%, 4, "\" ) , Section( %OBJE.FILE[1]%, 5, "\" ) )

Further nested TextIf(...) functions can cope with 3 folders, 2 folders, etc.

Re: Media File Names in queries

Posted: 01 Jun 2022 09:45
by Little.auk
Thanks Mike,

I knew there wouldn't be a simple answer!

My longest paths in my Media folder are 7 levels deep, so I decided to build from the bottom up. I found the easiest way to keep the syntax right was to start with the expression
=TextIf(Section(%OBJE.FILE%,3,"\") = "",Section(%OBJE.FILE%,2,"\"),"END") (as the MEDIA Root directory contains directories only). I then replaced "END" by cutting and pasting the "TestIf" expression, and updating the numbers. It only took a minute or so to nest as far as TextIf(Section(%OBJE.FILE%,8,"\")="", a level more than I have actually got. I then changed the final "END" to "MORE DIRECTORIES!" as a prompt should I exceed the current number of levels.

It works perfectly, thank you - I have now used it with Section(%SOUR.OBJE>FILE%,3,"\") to extract the file names in a Sources query.

Re: Media File Names in queries

Posted: 01 Jun 2022 18:16
by Little.auk
Hi Mike,

The Section(...) Function is so useful!

I am using AS and I use " : " (SPACE COLON SPACE). to split the elements of my customised Source Titles as per -

Baptism : Ryhill, Yorkshire, England :7 Mar 1897 : ROLLIN Sarah : [A0004-0001]

I wasn't sure that the Section function would accept " : " as the section separator - but it does! So that's a method for extracting data from Source Titles taken off my Wish List!

Re: Media File Names in queries

Posted: 01 Jun 2022 19:30
by tatewise
Peter, I hope you know where to find the details of what each function offers.
In FH, open Help > Family Historian Help
Then in the Contents open General Topics + Advanced Topics + Understanding Functions + Functions (all)
Then select the function such as Section where it says it allows one or more characters as separator characters to define the 'boundaries' of each section.

You will find other useful help pages nearby.

Re: Media File Names in queries

Posted: 02 Jun 2022 09:17
by Little.auk
I have both Understanding Functions and Understanding Expressions downloaded to my PC for easy access.

However, as I had already built the nested expression based on your example, I just tested "space-colon-space" myself -- Another example of "Reading the manual" being the last resort!