{"id":648,"date":"2016-08-20T11:09:48","date_gmt":"2016-08-20T16:09:48","guid":{"rendered":"http:\/\/www.lorenzcom.com\/?p=648"},"modified":"2020-12-03T07:27:43","modified_gmt":"2020-12-03T13:27:43","slug":"pathmaker","status":"publish","type":"post","link":"https:\/\/lorenzcom.com\/?p=648","title":{"rendered":"PathMaker"},"content":{"rendered":"<h3>PathMaker ( thePath , theFile , pathSeparator )<\/h3>\n<p>PathMaker returns a properly formatted folder and\/or file path by processing and combining thePath, theFile and pathSeparator.<\/p>\n<ul>\n<li>Easily change path separator in thePath.<\/li>\n<li>Preserves FileMaker Pro file reference prefixes (file:, filemac:, and filewin:).<\/li>\n<li>Conforms different separators in thePath to one only.<\/li>\n<li>Replaces errant separators in theFile with underscores.<\/li>\n<li>Separator defaults to the first path separator in thePath or to the system path separator if pathSeparator is blank.<\/li>\n<li>Concatenates thePath and theFile into a properly formatted file path.<\/li>\n<li>Use with the <a href=\"http:\/\/www.lorenzcom.com\/software\/pathparser\/\">PathParser<\/a> custom function for added path formatting control.<\/li>\n<\/ul>\n<h4>Parameters<\/h4>\n<ul>\n<li>thePath &#8211; Folder path.<\/li>\n<li>theFile &#8211; File name to append to thePath.<\/li>\n<li>pathSeparator &#8211; The separator used to separate folders in the thePath: \/:\\. If left blank the first found separator in thePath is used.<\/li>\n<\/ul>\n<h4>Examples<\/h4>\n<ul>\n<li>PathMaker ( &#8220;Macintosh HD2:Users\/user\/Documents:&#8221; , &#8220;&#8221; , &#8220;&#8221; ) = :Macintosh HD2:Users:user:Documents:<\/li>\n<li>PathMaker ( Get ( DocumentsPath ) , &#8220;&#8221; , &#8220;:&#8221; ) = :Macintosh HD2:Users:user:Documents:<\/li>\n<li>PathMaker ( Get ( DocumentsPath ) &amp; &#8220;My Folder&#8221; , &#8220;Untitled:\/1.txt&#8221; , &#8220;&#8221; ) = \/Macintosh HD2\/Users\/user\/Documents\/My Folder\/Untitled__1.txt<\/li>\n<li>PathMaker ( &#8220;file:&#8221; &amp; Get ( DocumentsPath ) , &#8220;Invoice.pdf&#8221; , &#8220;&#8221; ) = file:\/Macintosh HD2\/Users\/user\/Documents\/Invoice.pdf<\/li>\n<li>PathMaker ( Get ( DocumentsPath ) &amp; &#8220;My Folder:Brochures:&#8221; , &#8220;Untitled1.pdf&#8221; , &#8220;&#8221; ) = \/Macintosh HD2\/Users\/user\/Documents\/My Folder\/Brochures\/Untitled1.pdf<\/li>\n<li>PathMaker ( Get ( DocumentsPath ) &amp; &#8220;My Folder:Brochures:&#8221; , &#8220;Untitled1.pdf&#8221; , &#8220;\\\\&#8221; ) = \\Macintosh HD2\\Users\\user\\Documents\\My Folder\\Brochures\\Untitled1.pdf<\/li>\n<\/ul>\n<p><strong>PathMaker code:<\/strong> 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. <a href=\"\/docs\/FileMaker\/PathMaker.zip\">Download the code in a text file from here.<\/a><\/p>\n<form><textarea id=\"&lt;?php\"> style=&#8221;width:100%; height:180px; font-family:Arial,Helvetica; font-size:.90em; line-height:normal;&#8221;&gt;&lt;!&#8211;raw&#8211;&gt;Let ( [&lt;br \/&gt;<br \/>\n\/\/PATH: Default to NULL if thePath is empty.&lt;br \/&gt;<br \/>\np =  If ( IsEmpty ( Trim ( thePath ) ) ; &#8220;&#8221; ; thePath ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/FM PREFIX: Preserve file reference prefix.&lt;br \/&gt;<br \/>\nfrp = Middle ( p ; 1 ; Position ( p ; &#8220;:&#8221; ; 1 ; 1 ) ) ;&lt;br \/&gt;<br \/>\nfrn = GetAsBoolean ( PatternCount ( &#8220;xfile:xfilemac:xfilewin:xfmnet:&#8221; ; &#8220;x&#8221; &amp; Trim ( frp ) ) ) ;&lt;br \/&gt;<br \/>\np = If ( frn ; Replace ( p ; 1 ; Length ( frp ) ; &#8220;&#8221; ) ; p ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/SYSTEM PLATFORM. -1 = OS 9, 1 = OSX, -2 = WIndows.&lt;br \/&gt;<br \/>\nsp = Abs ( Get ( SystemPlatform ) ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/PATH SEPARATOR: Guess path separator based on platform.&lt;br \/&gt;<br \/>\nps = Left ( If ( sp = 1 ; Filter ( p ; &#8220;:\/\\\\&#8221; ) ; Filter ( p ; &#8220;\\\/&#8221; ) ) ; 1 ) ;  \/\/Precedence importaant.&lt;br \/&gt;<br \/>\nps = If ( IsEmpty ( ps ) ; &#8220;\/&#8221; ; ps ) ;&lt;br \/&gt;<br \/>\n\/\/Insure pathSeparator is a valid character before substituting path separators.&lt;br \/&gt;<br \/>\ns = Left ( Filter ( pathSeparator ; &#8220;\/:\\\\&#8221; ) ; 1 ) ;&lt;br \/&gt;<br \/>\n\/\/If invalid, use the separator guessed from the sent path.&lt;br \/&gt;<br \/>\ns = If ( IsEmpty ( s ) ; ps ; s ) ;&lt;br \/&gt;<br \/>\n\/\/Set all path separators to the proper value.&lt;br \/&gt;<br \/>\np = Substitute ( If ( sp = 1 ; Substitute ( p ; [ &#8220;:&#8221; ; s ] ) ; p ) ; [ &#8220;\/&#8221; ; s ]  ; [ &#8220;\\\\&#8221; ; s ] ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Add path separator to the right if it does not exist.&lt;br \/&gt;<br \/>\np = p &amp; If ( IsEmpty ( p ) or Right ( p ; 1 ) = s ; &#8220;&#8221; ; s ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/PATH LIST: Separate path to a list.&lt;br \/&gt;<br \/>\npl = Substitute ( p ; s ; &#8220;\u00b6&#8221; ) ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/PATH STRING.&lt;br \/&gt;<br \/>\np = Substitute ( MiddleValues ( pl ; 1 ; ValueCount ( pl ) ) ; &#8220;\u00b6&#8221; ; s ) ;&lt;br \/&gt;<br \/>\n\/\/Prepend file reference prefix and add the separator to the left if it does not exist.&lt;br \/&gt;<br \/>\np = If ( frn ; frp  ; &#8220;&#8221; ) &amp; If ( IsEmpty ( p ) or Left ( p ; 1 ) = s ; &#8220;&#8221; ; s ) &amp; p ;&lt;\/p&gt;<br \/>\n&lt;p&gt;\/\/Replace path separators from file name, if it exists, with a &#8220;_&#8221;.&lt;br \/&gt;<br \/>\nf = Substitute ( theFile ; [ &#8220;:&#8221; ; &#8220;_&#8221; ] ; [ &#8220;\/&#8221; ; &#8220;_&#8221; ]  ; [ &#8220;\\\\&#8221; ; &#8220;_&#8221; ] )&lt;br \/&gt;<br \/>\n] ;&lt;\/p&gt;<br \/>\n&lt;p&gt;If ( pathSeparator = &#8220;?&#8221; ; &#8220;PathMaker ( thePath , theFile , pathSeparator[:\/\\] )&#8221; ; p &amp; f )  \/\/Send back the made path.&lt;\/p&gt;<br \/>\n&lt;p&gt;)&lt;br \/&gt;<br \/>\n\/* PathMaker ( thePath , theFile , pathSeparator )&lt;\/p&gt;<br \/>\n&lt;p&gt;Returns a properly formatted folder and\/or file path by processing and combining thePath, theFile and pathSeparator.&lt;\/p&gt;<br \/>\n&lt;p&gt;    Easily change path separator in thePath.&lt;br \/&gt;<br \/>\n    Preserves FileMaker Pro file reference prefixes (file:, filemac:, and filewin:).&lt;br \/&gt;<br \/>\n    Conforms different separators in thePath to one only.&lt;br \/&gt;<br \/>\n    Replaces errant separators in theFile with underscores.&lt;br \/&gt;<br \/>\n    Separator defaults to the first path separator in thePath or to the system path separator if pathSeparator is blank.&lt;br \/&gt;<br \/>\n    Concatenates thePath and theFile into a properly formatted file path.&lt;br \/&gt;<br \/>\n    Use with the PathParser custom function for added path formatting control.&lt;\/p&gt;<br \/>\n&lt;p&gt;Parameters&lt;\/p&gt;<br \/>\n&lt;p&gt;    thePath &#8211; A folder path.&lt;br \/&gt;<br \/>\n    theFile &#8211; A file name to append to thePath.&lt;br \/&gt;<br \/>\n    pathSeparator &#8211; The separator used to separate folders in the thePath: \/:\\. If left blank the first found separator in thePath is used.&lt;\/p&gt;<br \/>\n&lt;p&gt;Examples&lt;\/p&gt;<br \/>\n&lt;p&gt;    PathMaker ( &#8220;Macintosh HD2:Users\/user\/Documents:&#8221; , &#8220;&#8221; , &#8220;&#8221; ) = :Macintosh HD2:Users:user:Documents:&lt;br \/&gt;<br \/>\n    PathMaker ( Get ( DocumentsPath ) , &#8220;&#8221; , &#8220;:&#8221; ) = :Macintosh HD2:Users:user:Documents:&lt;br \/&gt;<br \/>\n    PathMaker ( Get ( DocumentsPath ) &amp; &#8220;My Folder&#8221; , &#8220;Untitled:\/1.txt&#8221; , &#8220;&#8221; ) = \/Macintosh HD2\/Users\/user\/Documents\/My Folder\/Untitled__1.txt&lt;br \/&gt;<br \/>\n    PathMaker ( &#8220;file:&#8221; &amp; Get ( DocumentsPath ) , &#8220;Invoice.pdf&#8221; , &#8220;&#8221; ) = file:\/Macintosh HD2\/Users\/user\/Documents\/Invoice.pdf&lt;br \/&gt;<br \/>\n    PathMaker ( Get ( DocumentsPath ) &amp; &#8220;My Folder:Brochures:&#8221; , &#8220;Untitled1.pdf&#8221; , &#8220;&#8221; ) = \/Macintosh HD2\/Users\/user\/Documents\/My Folder\/Brochures\/Untitled1.pdf&lt;br \/&gt;<br \/>\n    PathMaker ( Get ( DocumentsPath ) &amp; &#8220;My Folder:Brochures:&#8221; , &#8220;Untitled1.pdf&#8221; , &#8220;\\\\&#8221; ) = \\Macintosh HD2\\Users\\user\\Documents\\My Folder\\Brochures\\Untitled1.pdf&lt;br \/&gt;<br \/>\n*\/&lt;!&#8211;\/raw&#8211;&gt;<\/textarea><br \/>\n<input form=\"\" type=\"text\" \/> type=&#8221;button&#8221; value=&#8221;Select All&#8221; \/&gt; <input type=\"reset\" value=\"Reset\" \/><\/form>\n","protected":false},"excerpt":{"rendered":"<p>PathMaker ( thePath , theFile , pathSeparator ) PathMaker returns a properly formatted folder and\/or file path by processing and combining thePath, theFile and pathSeparator. Easily change path separator in thePath. Preserves FileMaker Pro file reference prefixes (file:, filemac:, and <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/lorenzcom.com\/?p=648\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,14],"tags":[],"_links":{"self":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/648"}],"collection":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=648"}],"version-history":[{"count":23,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions"}],"predecessor-version":[{"id":875,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions\/875"}],"wp:attachment":[{"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lorenzcom.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}