In 4D versions prior to version 12, coding strings for platform independence could be combersome. 4D v12 commands greatly simplify the task.
As an example, assume the goal is to create an external database in a prescribed location outside any dependence on any standard 4D file location and the operating system could be Mac or Windows:
Though 4D document paths require system specific string syntax, we are going to start by prescribing the path in POSIX syntax and then build and confirm the target directory location on the boot drive step by step.
The OS needs to be determined in the first step. The new v12 command Convert path POSIX to system on the Mac OS includes the root drive designation in the conversion but does not included it on Windows. The 4D command System folder will return the absolute path to the active system folder, from which the designation of the root drive is obtained.
$Path_T:="/myDirectory/" PLATFORM PROPERTIES($Platform_L) If ($Platform_L=Mac OS) $Path_T:=Convert path POSIX to system($Path_T) Else // Root may not be the "c" drive // $Root_T:=System folder $Ndx:=Position(":";$Root_T) $Root_T:=Substring($Root_T;1;$Ndx) $Path_T:=$Root_T+Convert path POSIX to system($Path_T) End if |
Now confirm the validity of the target directory path and when not valid, create the needed folder.
Note the use of the new 4D v12 System Documents constant Folder separator in the build of the path to include the "Externals" directory. This new constant is platform smart.
If (Test path name($Path_T)#Is a directory) CREATE FOLDER($Path_T) End if $Path_T:=$Path_T+Folder separator+"Externals"+Folder separator If (Test path name($Path_T)#Is a directory) CREATE FOLDER($Path_T) End if $Path_T:=$Path_T+"myExtDB" |
Finally, create the external database in the new target directory.
Begin SQL CREATE DATABASE IF NOT EXISTS DATAFILE :$Path_T; End SQL |