System.IOUtils.TPath.Combine
Delphi
class function Combine(const Path1, Path2: string; const ValidateParams: Boolean = True): string; overload; inline; static;
class function Combine(const Path1, Path2, Path3: string; const ValidateParams: Boolean = True): string; overload; static;
class function Combine(const Path1, Path2, Path3, Path4: string; const ValidateParams: Boolean = True): string; overload; static;
class function Combine(const Paths: array of string; const ValidateParams: Boolean = True): string; overload; static;
C++
static System::UnicodeString __fastcall Combine(const System::UnicodeString Path1, const System::UnicodeString Path2, const bool ValidateParams = true)/* overload */;
static System::UnicodeString __fastcall Combine(const System::UnicodeString Path1, const System::UnicodeString Path2, const System::UnicodeString Path3, const bool ValidateParams = true)/* overload */;
static System::UnicodeString __fastcall Combine(const System::UnicodeString Path1, const System::UnicodeString Path2, const System::UnicodeString Path3, const System::UnicodeString Path4, const bool ValidateParams = true)/* overload */;
static System::UnicodeString __fastcall Combine(const System::UnicodeString *Paths, const System::NativeInt Paths_High, const bool ValidateParams = true)/* overload */;
プロパティ
| 種類 | 可視性 | ソース | ユニット | 親 |
|---|---|---|---|---|
| function | public | System.IOUtils.pas System.IOUtils.hpp |
System.IOUtils | TPath |
説明
2 つのパス文字列を結合します。
Combine を呼び出すと、2 つの異なるパスを結合して新しいパスを取得できます。 第 2 パスが絶対パスであれば、Combine はそれをそのまま返し、そうでない場合、Combine は第 1 パスに第 2 パスを連結して返します。
このメソッドに必要なパラメータの一覧を以下の表に示します。
| 名前 | 意味 |
|---|---|
|
Path1 |
第 1 パス。 Path1 は、Path2 のルートとして使用されます。 |
|
Path2 |
Path1 に連結されるパス |
メモ: 指定されたパスに無効な文字が含まれていた場合、Combine は例外を発生させます。
例
以下の例では、TPath.combine 関数を使用して 2 つのファイルパスを結合しています。次の表は、想定される結果と、それぞれのケースについて概説しています。
| 入力 | 出力 | 説明 |
|---|---|---|
TPath.combine('E:\somewhere\', 'there\file.txt')
|
'E:\somewhere\there\file.txt'
|
これは、この API を使用する際の推奨方法です。この場合、出力は .txt ファイルへのフルパスです。 |
TPath.combine('E:\somewhere', 'there\file.txt')
|
'E:\somewhere\there\file.txt'
|
ご覧の通り、TPath.combine は 2 つのパスを組み合わせ、最初のパスがバックスラッシュで終わっていない場合でも、`.txt` ファイルへの正しいフルパスを生成します。 |
TPath.combine('E:\somewhere', '\there\file.txt')
|
'\there\file.txt'
|
この例では、2 番目のパスがバックスラッシュで始まる場合、TPath.combine はパスを結合しません。その結果、関数は 2 番目のパスのみを返します。 |
TPath.combine('E:\somewhere', 'C:\there\file.txt')
|
'C:\there\file.txt'
|
TPath.combine は、2 つの異なるパスを組み合わせることはできません。この場合、単に2番目のパスを出力として返します。
|
メモ: .\ と ..\ はまだ解決されていないことに注意してください。