Tech Tip: Utility method to perform "Get 4D Folder" on the server machine
PRODUCT: 4D | VERSION: 12.3 | PLATFORM: Mac & Win
Published On: March 17, 2012
This utility method, OnServer_Get_4D_Folder, is great for when working Client-Server or creating a Component that requires pathnames on the server. It also shows how to enhanced the method to provide the pathname to a folder that 4D does not have a standard constant for.
The 4D Pop Constants editor was used to make the constant Backup Prefs Folder whish has a value of 99, something well out of the range of constants 4D uses for the command Get 4D Folder.
If (True) If (False) Begin SQL /* OnServer_Get_4D_Folder Purpose: Get the pathname of a folder on the server machine $0 - TEXT - Get the absolute local path on the server drive $1 - LONGINT - Type of folder $FolderType_L of 99 is Preferences/Backup folder User constant "Backup Prefs Folder" If it does not exist, it is created Method Properties: Invisible / Shared with Host / Execute on Server */ End SQL End if C_TEXT($MethodName_T) $MethodName_T:=Current method name //============= Declare Variables ============== //method_parameters_declarations C_LONGINT($FolderType_L;$1) C_TEXT($0;$Path_T) //------------------------------------------------ //method_wide_constants_declarations //------------------------------------------------ //local_variable_declarations End if //============== Initialize and Setup ============== $Path_T:="" $FolderType_L:=$1 // Filter any bad folder type values, no alert dialogs on the server // ( If ((($FolderType_L>=Active 4D Folder) & ($FolderType_L<=HTML Root Folder)) | \ ($FolderType_L=Backup Prefs Folder)) // ) //================ Method Actions ============== If ($FolderType_L=Backup Prefs Folder) $Path_T:=Get 4D folder(Database Folder;*)+\ "Preferences"+Folder separator+\ "Backup"+Folder separator If (Test path name($Path_T)#Is a directory) CREATE FOLDER($Path_T) End if Else $Path_T:=Get 4D folder($FolderType_L;*) End if //================ Clean up and Exit ============== End if $0:=$Path_T |