Sample code for 30+ languages & platforms
Visual FoxPro

Delete Files Matching Pattern

See more FTP Examples

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

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loFtp
LOCAL lnNumDeleted

lnSuccess = 0

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

loFtp = CreateObject('Chilkat.Ftp2')

loFtp.Hostname = "www.chilkatsoft.com"
loFtp.Username = "MyLogin"
loFtp.Password = "MyPassword"

* Connect and login to the FTP server.
lnSuccess = loFtp.Connect()
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

* Change to the remote directory where the files to be deleted are located.
* for the FTP account.
lnSuccess = loFtp.ChangeRemoteDir("junk")
IF (lnSuccess <> 1) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

* Delete all files with filenames matching "ftp_*.asp"
lnNumDeleted = loFtp.DeleteMatching("ftp_*.asp")
IF (lnNumDeleted < 0) THEN
    ? loFtp.LastErrorText
    RELEASE loFtp
    CANCEL
ENDIF

lnSuccess = loFtp.Disconnect()

? STR(lnNumDeleted) + " Files Deleted!"

RELEASE loFtp