Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
Delphi for .NET FCL Examples Reference
Path namespace
System.IO
Declaration
type Path = class sealed;
Description
Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.
Example
program System_IO_Path;

{$APPTYPE CONSOLE}
{$AUTOBOX ON}


uses System.IO, System.Collections;

type
  PathTest = class
  public
    class procedure Main;
  end;

{ PathTest }

class procedure PathTest.Main;
var
  c: WideChar;
  i:integer;
  path3: string;
  path2: string;
  path1: string;
begin
  path1 := 'c:\temp\MyTest.txt';
  path2 := 'c:\temp\MyTest';
  path3 := 'temp';

  if Path.HasExtension(path1) then
    Console.WriteLine('{0} has an extension.', path1);

  if (Path.HasExtension(path2) = False) then
    Console.WriteLine('{0} has no extension.', path2);

  if (Path.IsPathRooted(path3) = False) then
    Console.WriteLine('The string {0} contains 
                       no root information.', path3);

  Console.WriteLine('The full path of {0} is {1}.', 
                    path3, 
                    Path.GetFullPath(path3));
                    
  Console.WriteLine('{0} is the location for temp files.', 
                    Path.GetTempPath);
                    
  Console.WriteLine('{0} is a file available for use.', 
                    Path.GetTempFileName);
                    
  Console.WriteLine(''#13#10'The set of invalid 
                     characters in a path is:');
  
  Console.WriteLine('(Note that the wildcard characters ''*'' 
                     and ''?'' are not invalid.):');

  for i := 0 to  -1 + Length(Path.InvalidPathChars) do
  begin
    c := Path.InvalidPathChars[i];
    Console.WriteLine(c);
  end;
end;

//test program
begin
  PathTest.Main;
end.
Example output
c:\temp\MyTest.txt has an extension.

c:\temp\MyTest has no extension.

The string temp contains no root information.

The full path of temp is 

C:\Documents and Settings\Administrator\My Documents\
Borland Studio Projects\FCLClassesHelp\temp.

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ 
is the location for temporary files.

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\tmpF7.tmp 
is a file available for use.

The set of invalid characters in a path is:
(Note that the wildcard characters 
'*' and '?' are not invalid.):

"
<
>
|
|
¶
§
-
|
^
¡

Looking for Delphi for .NET demos / source code samples? Look no further, Delphi for .NET FCL Examples Reference is what you are searching for!

Explore Delphi Programming

About.com Special Features

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.