Home  |  Delphi .net Home  |  System.IO.Path  |  Combine Method
Combine  
Method  
Combines two Path strings into a single Path string
Path Class
System.IO NameSpace
CF1.  Function Combine ( Path1:StringPath1 : String; Path2 : String; ) : String; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
This is a bit of a fussy method. If Path1 or Path2 contain whitespace characters, then they are simply combined. Otherwise, the resultant string will be the concatenation of Path1 and Path2 - a combined path string - unless Path2 is absolute (IsPathRooted = true). In that case, Path2 is simply returned alone.
 
If a concatenation is returned, an appropriate separator character is added between them as needed to make a legitimate path string.
Microsoft MSDN Links
System.IO
System.IO.Path
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Path1, Path2, Path3 : String;

begin
  Path1 := 'C:\Delphi';
  Path2 := 'Testing\DelphiBasics.txt';
  Path3 := System.IO.Path.Combine(Path1, Path2);

  Console.WriteLine('Path1 = "{0}"', Path1);
  Console.WriteLine('Path2 = "{0}"', Path2);
  Console.WriteLine('Path3 = "{0}"', Path3);

  Console.Readline;
end.
Show full unit code
  Path1 = "C:\Delphi"
  Path2 = "Testing\DelphiBasics.txt"
  Path3 = "C:\Delphi\Testing\DelphiBasics.txt"
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author