Xbase++
Xbase++
Get Number of FIles in Directory, not including sub-directories
See more FTP Examples
_LANGUAGE_ example demonstrating how to get the number of files in a directory not including sub-directories.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oFtp
LOCAL i
LOCAL n
LOCAL nFileCount
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 := "ftp.example.com"
oFtp:Username := "login"
oFtp:Password := "password"
// Connect and login to the FTP server.
nSuccess := oFtp:Connect()
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
// The ListPattern property is our directory listing filter.
// The default value is "*", which includes everything.
? oFtp:ListPattern
// Fetch the current remote directory contents by
// calling GetDirCount
n := oFtp:GetDirCount()
IF (n < 0)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
IF (n > 0)
// Loop over the directory contents, incrementing the count
// each time it is NOT a directory.
nFileCount := 0
FOR i := 0 TO n - 1
// Is this NOT a sub-directory?
IF (oFtp:GetIsDirectory(i) != 1)
nFileCount := nFileCount + 1
// Display the filename
? oFtp:GetFilename(i)
ENDIF
NEXT
? "Total number of files = " + Str(nFileCount)
ENDIF
nSuccess := oFtp:Disconnect()
oFtp:destroy()