Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Get Number of FIles in Directory, not including sub-directoriesVB.NET example demonstrating how to get the number of files in a directory not including sub-directories. Download: Chilkat .NET Assemblies Dim ftp As New Chilkat.Ftp2() Dim success As Boolean ' Any string unlocks the component for the 1st 30-days. success = ftp.UnlockComponent("Anything for 30-day trial") If (success <> true) Then MsgBox(ftp.LastErrorText) Exit Sub End If ftp.Hostname = "www.myFtpServer.com" ftp.Username = "****" ftp.Password = "****" ' Connect and login to the FTP server. success = ftp.Connect() If (success <> true) Then MsgBox(ftp.LastErrorText) Exit Sub End If ' The ListPattern property is our directory listing filter. ' The default value is "*", which includes everything. TextBox1.Text = TextBox1.Text & ftp.ListPattern & vbCrLf ' Fetch the current remote directory contents by ' accessing the NumFilesAndDirs property. Dim i As Long Dim n As Long n = ftp.NumFilesAndDirs If (n < 0) Then MsgBox(ftp.LastErrorText) Exit Sub End If If (n > 0) Then ' Loop over the directory contents, incrementing the count ' each time it is NOT a directory. Dim fileCount As Long fileCount = 0 For i = 0 To n - 1 ' Is this NOT a sub-directory? If (ftp.GetIsDirectory(i) <> true) Then fileCount = fileCount + 1 ' Display the filename TextBox1.Text = TextBox1.Text & ftp.GetFilename(i) & vbCrLf End If Next TextBox1.Text = TextBox1.Text & "Total number of files = " _ & fileCount & vbCrLf End If ftp.Disconnect() |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.