Skip to content

Instantly share code, notes, and snippets.

@seanwalsh
Created December 29, 2014 00:44
FileMaker custom function to create a file path.
/*
---------------------------------------------------------------
CUSTOM FUNCTION :: formatFilePath ( format )
---------------------------------------------------------------
formatFilePath © 2006 Sean Walsh
Developed by: Sean Walsh
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------------------------------
CUSTOM FUNCTION :: HELP
---------------------------------------------------------------
ON THE WEB
Help, an example file or to comment on this custom function visit;
http://www.solventllc.com/filemaker/custom_function/formatfilepath.php
---------------------------------------------------------------
CUSTOM FUNCTION :: REFERENCE
---------------------------------------------------------------
Format:
formatFilePath ( format )
Parameters:
format - the text with paramters to be replaced.
Parameter listing:
%f = Full local path; filemac: or filewin:
%f/ = Full local path with leading slash; filemac:/ or filewin:/
%F = Full local network path, windows only; filewin:
%F/ = Full local network path, windows only with leading slash; filewin://
%n" = FileMaker network path; fmnet:
%n/ = FileMaker network path with leading slash; fmnet:/
%r = Relative path without platform name; file:
%R = Relative path with platform name; filemac: or filewin:
Data type returned:
text
Description:
Formats the parameters into the filepath type for proper file paths.
Examples:
formatFilePath ( "%f" & Get ( DesktopPath ) ) returns 'filemac:/Macintosh HD/Users/admin/Desktop/' on a Mac
formatFilePath ( "%f/" & Field1 ) returns 'filemac:/Macintosh HD/Users/admin/Desktop/' when on a Mac and Field1 contains 'Macintosh HD/Users/admin/Desktop/'
formatFilePath ( "%n192.168.10.10/database.fp7") returns fmnet:/192.168.10.10/database.fp7
--
*/
Let (
[
$platform = Case ( Abs ( Get ( SystemPlatform ) ) = 1; "mac"; "win" )
];
Substitute (
format;
[ "%f"; "file" & $platform & ":" ]; // FULL LOCAL PATH
[ "%f/"; "file" & $platform & ":/" ]; // FULL LOCAL PATH--WITH LEADING SLASH
[ "%F"; Case ( $platform = "win"; "file" & $platform & "://" )]; // FULL LOCAL NETWORK PATH, WINDOWS ONLY
[ "%F/"; Case ( $platform = "win"; "file" & $platform & "://" )]; // FULL LOCAL NETWORK PATH--WITH LEADING SLASH, WINDOWS ONLY
[ "%n"; "fmnet:/"]; // FILEMAKER NETWORK PATH
[ "%n/"; "fmnet://"]; // FILEMAKER NETWORK PATH--WITH LEADING LASH
[ "%r"; "file:" ]; // RELATIVE PATH WITHOUT PLATFORM NAME
[ "%R"; "file" & $platform & ":" ] // RELATIVE PATH WITH PLATFORM NAME
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment