Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Delete Files Matching Pattern
See more FTP Examples
The DeleteMatching method deletes all files in the current remote directory matching a wildcarded filename.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.Ftp2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
numDeleted: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp := TFtp2.Create;
ftp.Hostname := 'www.chilkatsoft.com';
ftp.Username := 'MyLogin';
ftp.Password := 'MyPassword';
// Connect and login to the FTP server.
success := ftp.Connect();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Change to the remote directory where the files to be deleted are located.
// for the FTP account.
success := ftp.ChangeRemoteDir('junk');
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Delete all files with filenames matching "ftp_*.asp"
numDeleted := ftp.DeleteMatching('ftp_*.asp');
if (numDeleted < 0) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
success := ftp.Disconnect();
WriteLn(numDeleted + ' Files Deleted!');
ftp.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.