GetFileName ( FullName )
Extracts Filename from the Full Path Name
Average rating: 3.5 (50 votes) Log in to vote
William Donelson Mine http://www.none.com |
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Extracts Filename from the Full Path Name
Dependencies : None
Comments
Bernhard Schulz, Salzburg/Austria Oct 9, 2009 |
||
Function above is wrong. This works for me: Let( [ Delimiter = "/"; Counter = PatternCount ( FullName ; Delimiter ) ]; Case( Counter = 0 ; FullName ; Counter > 30 ; "ERROR: too many directories" ; getFileName ( Right ( FullName; Length(FullName) - Position ( FullName; Delimiter; 1; 1) ) ) ) ) |
||
David Jan 25, 2010 |
||
What about this (makes it non recursive): Let( [ Delimiter = "/"; Counter = PatternCount(FullName;Delimiter); Parts = Substitute(FullName;"/";"¶") ]; Case( Counter = 0; FullName; Counter > 30; "Error: too many directories"; GetValue(Parts;ValueCount(Parts)) ) ) |
||
Michael, Austin Oct 7, 2010 |
||
Love the last version of this custom formula, but one question. What is the purpose of setting a value for Delimiter? Doesn't replacing the word Delimiter with "/" achieve the same results? | ||
Sean, Private Mar 3, 2011 |
||
How about this: getFileName ( file ) Right ( file ; Length ( file ) - Position ( file ; "." ; 1 ; PatternCount ( file ; "." ) ) ) Non-recursive and it doesn't matter how many directories there are. |
||
Sean, Private Mar 3, 2011 |
||
Sorry, that was for my get extension function. getFileName ( path ) Right ( path ; Length ( path ) - Position ( path ; "/" ; 1 ; PatternCount ( path ; "/" ) ) ) |
||
Ben S-W, London Jan 16, 2014 |
||
Thanks David Tampa your script (underneath) worked for me all i needed to do was replace FullName with the name of my field containing the file path. I have been working with text find and replace for hours before I decided to use FM Pro. Wish I started there! Let( [ Delimiter = "/"; Counter = PatternCount(FullName;Delimiter); Parts = Substitute(FullName;"/";"¶") ]; Case( Counter = 0; FullName; Counter > 30; "Error: too many directories"; GetValue(Parts;ValueCount(Parts)) ) |
||
Matt Larson Aug 18, 2015 |
||
Here's one that will handle an unlimited number of directories and file paths (uses recursion): GetFileName(FilePaths; Iteration) Let( [ i = If(not IsEmpty(Iteration); Iteration; 1); ~Path = GetValue(FilePaths; i); ~Name = Right(~Path; Length(~Path) - Position(~Path; "/"; 1; PatternCount(~Path; "/"))) ]; If( i ≤ ValueCount(FilePaths); If(i > 1; "¶") & ~Name & GetFileName(FilePaths; i + 1) ) ) |
||
Louis Benainous, Berkeley, CA Mar 3, 2017 |
||
Here's my calculation field where you would need to replace "FullPath" with the field name of the full path that you are using -- critique welcome: Right ( FullPath ; Length ( FullPath ) - Position ( FullPath ; "/" ; 1 ; PatternCount ( FullPath ; "/" ) ) ) |
||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.