PathParser
PathParser ( thePath , returnElementPHFNE )
PathParser returns the path directory, 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.
- The path and filename element separation is set to the leftmost path separator in thePath.
- Works with the thePath string as passed – it does not format thePath, except to prepend a missing path separator when returning directory path or home requests.
- 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 passed number:
- p (path) – Returns the path directory, without the filename and extension.
- h or ~ (home) – Returns the home directory path, without the system drive information.
- f (fullfilename) – Returns just the filename and extension, without the path directory.
- n (name) – Returns just the filename, without the path directory and without the file extension.
- e (extension) – Returns just the file extension, without the path directory and without filename.
- +/-# (omit directories) – Returns the directory path after omitting the specified number of directories.
- A positive number omits directories forwards from the left of thePath.
- A negative number omits directories backwards from the right of thePath.
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 only 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 ).
PathParser code: Copy the selected code (click on Select All to highlight all the code) to the clipboard and paste it into a newly created Custom Function. Download the code in a text file from here.
Pingback:PathMaker - Lorenz Companies