Tech Tip: Utility method to determine if path is posix, windows, or mac
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: June 2, 2016
Below is an utility method to determine if the path type is posix, winows system, or mac system.
// Method name: UTIL_GET_PATH_TYPE // Determine if path is system or posix // // Parameters: // $1 - path // $0 - 0 if posix, 1 if windows, 2 if mac C_TEXT($path;$1) C_LONGINT($return;$0) C_BOOLEAN($found) If (Count parameters>=1) $path:=$1 $found:=Match regex("/";$path;1) Case of : ($found=True) //Posix $return:=0 : ($found=False) //system $found:=Match regex("\\\\";$path;1) Case of : ($found=True) //windows system $return:=1 : ($found=False) //mac system $return:=2 End case End case $0:=$return End if |
Note: This method assumes that special characters along with folder characters are not used in the folder names.
Example:
$path:="C:\\Users\\user1\\" $type:=UTIL_GET_PATH_TYPE ($path) //returns 1 for windows system $path:="Macintosh HD:Users:user1:" $type:=UTIL_GET_PATH_TYPE ($path) //returns 2 for mac system $path:="C:/Users/user1/" $type:=UTIL_GET_PATH_TYPE($path) //returns 0 for posix |
Commented by Timothy Tse on June 14, 2016 at 9:18 AM
$sep was unnecessary and has been removed now.
Commented by Leonard Soloniuk on June 14, 2016 at 8:51 AM
The variable $sep does not seem to be used once set and appears to be unnecessary