System.IOUtils.TPath.Combine

From RAD Studio API Documentation
Jump to: navigation, search

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 */;

Properties

Type Visibility Source Unit Parent
function public
System.IOUtils.pas
System.IOUtils.hpp
System.IOUtils TPath

Description

Combines two paths strings.

Call Combine to obtain a new combined path from two distinct paths. If the second path is absolute, Combine returns it directly; otherwise Combine returns the first path concatenated with the second one.


The following table lists the parameters expected by this method:

Name Meaning

Path1

The first path. Path1 is used as root for Path2.

Path2

The path that is concatenated with Path1.

Note: Combine raises an exception if the given paths contain invalid characters.

Examples

In the examples below, TPath.combine function is used to combine two file paths. The table below shows the expected result and briefly explains each case.

Input Output Description
TPath.combine('E:\somewhere\', 'there\file.txt') 'E:\somewhere\there\file.txt' This is the recommended way to use this API. In this case, the output is the full path to the .txt file.
TPath.combine('E:\somewhere', 'there\file.txt') 'E:\somewhere\there\file.txt' As you can see, TPath.combine combines two paths, even when the first path does not end with a backslash, resulting in the correct full path to the `.txt` file.
TPath.combine('E:\somewhere', '\there\file.txt') '\there\file.txt' In this example, TPath.combine does not combine the paths if the second path begins with a backslash. As a result, the function returns only the second path.
TPath.combine('E:\somewhere', 'C:\there\file.txt') 'C:\there\file.txt' TPath.combine cannot combine two different paths. In this case, it simply returns the second path as output.
Note: Please remember that .\ and ..\ are not resolved yet.

See Also