Sample code for 30+ languages & platforms
Xbase++

Delete Files Matching Pattern

See more FTP Examples

The DeleteMatching method deletes all files in the current remote directory matching a wildcarded filename.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oFtp
LOCAL nNumDeleted

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oFtp := CreateObject("Chilkat.Ftp2")

oFtp:Hostname := "www.chilkatsoft.com"
oFtp:Username := "MyLogin"
oFtp:Password := "MyPassword"

//  Connect and login to the FTP server.
nSuccess := oFtp:Connect()
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Change to the remote directory where the files to be deleted are located.
//  for the FTP account.
nSuccess := oFtp:ChangeRemoteDir("junk")
IF (nSuccess != 1)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

//  Delete all files with filenames matching "ftp_*.asp"
nNumDeleted := oFtp:DeleteMatching("ftp_*.asp")
IF (nNumDeleted < 0)
    ? oFtp:LastErrorText
    oFtp:destroy()
    RETURN
ENDIF

nSuccess := oFtp:Disconnect()

? Str(nNumDeleted) + " Files Deleted!"

oFtp:destroy()