Delphi Drawers

パスを連結

ファイルパスを連結します。
例えばフォルダパス+フォルダ名や、フォルダ+ファイル名といった結果を返します。

function fnConCastPath(strPath1:string; strPath2:string):string;
var
  strWallChar,strTempChar,strConCastPath:string;
begin
  //区切り文字を設定
  if Pos('/',strPath1 + strPath2) > 0 then begin
    strWallChar := '/';
  end else begin
    strWallChar := '\';
  end;
  //区切り文字置き換え1
  strPath1 := StringReplace(strPath1,'/','\',[rfReplaceAll]);
  strPath2 := StringReplace(strPath2,'/','\',[rfReplaceAll]);
  //パス1の末尾に区切り文字がない場合は付加
  strPath1 := IncludeTrailingPathDelimiter(strPath1);
  //パス2の先頭に区切り文字がある場合は消去
  if strPath2 <> '' then begin
    strTempChar := copy(strPath2, 1,1);
    if strTempChar = '\' then begin
      strPath2 := copy(strPath2,2,length(strPath2) - 1);
    end;
  end;
  //連結
  strConCastPath := strPath1 + strPath2;
  //区切り文字置き換え2
  strConCastPath := StringReplace(strConCastPath,'\',strWallChar,[rfReplaceAll]);
  fnConCastPath := strConCastPath;
end;
Copyright © 2006 Hikijishi All Rights Reserved.
[] [delphi][0.00217485427856445]