Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Demonstrate Directory Path Functions
Demonstrates the path functions GetDirectoryName, GetExtension, GetFileName, and GetFileNameWithoutExtension.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.FileAccess;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
fac: TFileAccess;
begin
fac := TFileAccess.Create;
// Note: Chilkat accepts either forward slash or backslash chars as directory separators..
WriteLn(fac.GetDirectoryName('/MyDir/MySubDir/myfile.ext'));
WriteLn(fac.GetDirectoryName('/MyDir/MySubDir'));
WriteLn(fac.GetDirectoryName('/MyDir/'));
WriteLn(fac.GetDirectoryName('/MyDir'));
WriteLn(fac.GetDirectoryName('/'));
WriteLn(fac.GetExtension('C:/mydir.old/myfile.ext'));
WriteLn(fac.GetExtension('C:/mydir.old/'));
WriteLn(fac.GetFileName('C:/mydir/myfile.ext'));
WriteLn(fac.GetFileName('C:/mydir/'));
WriteLn(fac.GetFileNameWithoutExtension('C:/mydir/myfile.ext'));
WriteLn(fac.GetFileNameWithoutExtension('C:/mydir/'));
WriteLn('---');
fac.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.