JCL_file_MakeFilePath

ファイルまたはフォルダのパスを作る。2つの文字列をディレクトリセパレータで連結する。macOSとWindowsの違いをフォルダ区切り文字の違いを吸収する。

使い方
$tempPath:=JCL_file_MakeFilePath(Document folder; “JIRO_TMP”)

引数
$1: フォルダーパス
$2: フォルダー名
$0: ファイルパス

使用例:

//リソースフォルダからフィールズを読み込む
$folderPath:=JCL_file_MakeFilePath(Get 4D folder(Database folder); "Resources")
$folderPath:=JCL_file_MakeFilePath($folderPath; "JCL4D_Resources")
$filePath:=JCL_file_MakeFilePath($folderPath; "fields.txt")

$fileText:=Document to text($filePath; UTF8 text without length)

ソースコード:

//JCL_file_MakeFilePath
//20110222 wat
//ファイルパスを生成

C_TEXT($1; $folder)
$folder:=$1  //フォルダ名
C_TEXT($2; $fileName)
$fileName:=$2  //ファイル名
C_TEXT($0; $outPath)

C_TEXT($separator)
$separator:=JCL_file_GetDirSeparator

C_LONGINT($length)
C_TEXT($char)

$length:=Length($folder)

//末尾の1文字取得
$latOfFolderChar:=Substring($folder; $length)
$firstOfFileChar:=Substring($fileName; 1; 1)

If ($latOfFolderChar=$separator)
	If ($firstOfFileChar=$separator)
		//どちらもセパレータ付きならフォルダからカット
		$folder:=Substring($folder; 1; $length-1)
		$outPath:=$folder+$fileName
		
	Else 
		//フォルダにセパレータがついていてファイルにセパレータがないならそのまま結合
		$outPath:=$folder+$fileName
		
	End if 
Else 
	//フォルダにセパレータがついていないなら、セパレータを入れて結合
	If ($firstOfFileChar=$separator)
		//ファイル名の最初にセパレータがついていたら
		$outPath:=$folder+$fileName
		
	Else 
		//どちらもセパレータなしならセパレータを入れて結合
		$outPath:=$folder+$separator+$fileName
		
	End if 
End if 

$0:=$outPath

ファイルパス作成といっても、内容は2つの引数で与えられた文字列をセパレータで連結しているだけ。第1引数はパスとして正しいことが前提。