Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Create Symbolic Link

See more FileAccess Examples

Demonstrates how to create a symbolic (soft) link.

Note: This example requires Chilkat v9.5.0.77 or greater.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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
  success: Boolean;
  fac: TFileAccess;
  target: string;
  symlink: string;

begin
  success := False;

  //  Chilkat supports symbolic links on both Windows and non-Windows operating systems.
  //  Note: On Windows, symbolic links and Windows shortcuts are two different things.
  //  On the Windows operating system, a process requires a special privilege to create
  //  a symbolic link (unless running as administrator).  

  fac := TFileAccess.Create;

  //  Here we create a symbolic link to point to qa_data/hamlet.xml
  //  
  target := 'qa_data/hamlet.xml';
  symlink := 'qa_output/symlink_hamlet.xml';
  success := fac.SymlinkCreate(target,symlink);
  if (success <> True) then
    begin
      WriteLn(fac.LastErrorText);
      Exit;
    end;

  //  Here we create a directory symbolic link.  The target is a directory (not a regular file)
  target := 'qa_data/xml/';
  symlink := 'qa_output/xml_dir';
  success := fac.SymlinkCreate(target,symlink);
  if (success <> True) then
    begin
      WriteLn(fac.LastErrorText);
      Exit;
    end;

  WriteLn('Success.');


  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.