Brian Dunning's FileMaker Custom Functions

PathParser ( thePath ; returnElementPHFNE )

PathParser returns the directory path, home directory, full filename and extension, filename, or extension from a folder and/or file path string.

  Average rating: 4.3 (13 votes) Log in to vote

Lewis Lorenz   Lewis Lorenz
Lorenz Companies
http://www.LorenzCom.com

Share on Facebook Share on Twitter

  Sample input:
PathParser ( "file:" & Get ( DocumentsPath ) & "Untitled.pdf" ; "p" )
PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "h" )
PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "fullfilename" )
PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "n" )
PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "e" )
PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "2" )
PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "-1" )
  Sample output:
file:/Macintosh HD2/Users/user/Documents/
/Users/user/Documents/
Untitled.pdf
Untitled
pdf
/user/Documents/
/Macintosh HD2/Users/user/

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

PathParser ( thePath , returnElementPHFNE )

PathParser returns the directory path, home directory, full filename and extension, filename, or extension from a folder and/or file path string.

- Easily extract path elements from thePath.
- Preserves FileMaker Pro file reference prefixes (file:, filemac:, and filewin:).
- Omit directories forwards or backwards from thePath.
- The home or ~ (tilde) element request returns the home path - path without Get ( SystemDrive ) prepended.
- Works with the thePath string as passed - it does not format thePath, except to prepend a missing path separator when returning path or home requests.
- Uses the leftmost path separator in thePath to delineate path elements.
- Use with the PathMaker custom function for added path formatting control.

Parameters:

- thePath - A folder and/or file path.
- returnElementPHFNE - The element in thePath to return. Determined from the first letter of the passed parameter or the number:
- [p]ath: Returns the directory path, without the filename and extension.
- [h]ome or ~: Returns the home directory path, without the system drive information.
- [f]ullfilename: Returns the filename and extension, without the path directory.
- [n]ame: Returns the filename, without the path directory and without the file extension.
- [e]xtension: Returns the file extension, without the path directory and without filename.
- [+/-#]: Returns the path after omitting the specified number (#) of directories from the left or right of thePath.
- A positive number omits directories forwards from the left.
- A negative number omits directories backwards from the right.

Examples:

- PathParser ( "file:" & Get ( DocumentsPath ) & "Untitled.pdf" ; "p" ) = file:/Macintosh HD2/Users/user/Documents/
- PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "h" ) = /Users/user/Documents/
- PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "fullfilename" ) = Untitled.pdf
- PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "n" ) = Untitled
- PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "e" ) = pdf
- PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "2" ) = /user/Documents/
- PathParser ( Get ( DocumentsPath ) & "Untitled.pdf" ; "-1" ) = /Macintosh HD2/Users/user/

Help:

- Passing '?' as the leftmost text in returnElementPHFNE returns this help text: PathParser ( thePath , returnElementPHFNE: [p]ath, [h]ome or [~], [f]ull name and extension, [n]ame, [e]xtension), [+/-#] omit # of directories ).

 

Comments

Lewis Lorenz   Lewis Lorenz, Lorenz Companies
Oct 23, 2016
I updated this function 10/23/2016 to allow skipping directories in thePath. User can send a positive or negative number in the returnElement parameter to skip directories either forward from the left or backwards from the right.
 
Robert R   Robert R, Brooksville, FL
Jan 21, 2018
I have tried this in FMPA 16 and can't get by the saving it as a custom function as it says "The specified parameter can't be found " refering to "thePath"

any thoughts or updates for FMPA 16
 
Lewis Lorenz   Lewis Lorenz, Lorenz Companies
Jan 25, 2018
I haven't had issues with this. Can you supply more information?
 
Steve   Steve, Dallas
May 8, 2018
I too am having the same issue with the error "The specified parameter can't be found" in reference to "thePath." I copied and pasted it directly from the site. Is there anything else that needs to be done prior to trying to save the custom function? Thank you in advance.
 
Lewis Lorenz   Lewis Lorenz, Lorenz Companies
May 9, 2018
I am happy to fix this, but I can not replicate this issue. Please contact me at lewis@lorenzcom.com with information about how you encountered this error.

Thank you.
 
Steve   Steve, Dallas
May 9, 2018
Sure, I will email you in a second. Thanks!
 
Steve   Steve, Dallas
May 9, 2018
Actually, I figured out what I was doing wrong. I had not set the Function Parameters. Thank you for your custom function and willingness to help. Much appreciated!
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.