Login  
Search All Forums
Dart Home | PowerTCP FTP for .NET | Custom Development Reply | PowerTCP FTP for .NET Topics | Forums   
AuthorForum: PowerTCP FTP for .NET
Topic: Recursive Listing of Entire Directory Tree
vbalsara
vipul.balsara@acnielsen.ca

From: Toronto, ON Canada
Posts: 3
Member Since: 01/03/05
posted January 3, 2005 11:58 AM

Hello, can someone provide some sample code in VB.NET of how to recursively scan through an entire Directory Tree and list all of the folders/subfolders and files?

thanks
vbalsara.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted January 3, 2005 12:09 PM

Here's a function I use:

   Public Sub GetAllFiles(ByVal SourceDir As String, ByRef FileList As ArrayList)
    Dim Dirs() As String = System.IO.Directory.GetDirectories(SourceDir)
    Dim s As String
    If Dirs.Length > 0 Then
      For Each s In Dirs
        GetAllFiles(s, FileList)
      Next
    End If
    Dim Files() As String = System.IO.Directory.GetFiles(SourceDir)
    For Each s In Files
      FileList.Add(s)
    Next
  End Sub

Here's an example using the function:

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim FileList As New ArrayList()
    GetAllFiles("c:\Test", FileList)
    Dim File As String
    For Each File In FileList
      System.Diagnostics.Debug.WriteLine(File)
    Next
  End Sub
vbalsara
vipul.balsara@acnielsen.ca

From: Toronto, ON Canada
Posts: 3
Member Since: 01/03/05
posted January 3, 2005 12:41 PM

Sorry, I should have been more explicit. I wanted to recurse an FTP Directory Tree using the Dart.PowerTCP.Ftp component and the associtated List() method.

Thank you
vbalsara.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted January 3, 2005 1:15 PM

Please see the Ftp.ExpandRemoteFiles Method in the Online help. There are code examples in there.
vbalsara
vipul.balsara@acnielsen.ca

From: Toronto, ON Canada
Posts: 3
Member Since: 01/03/05
posted January 3, 2005 3:08 PM

Thanks Tony. I tried this out however it does not provide the functionality that I require. This function call does not return all of the directories recursively, on the files contained in those directories.

any other tips?

thanks
vbalsara
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted January 3, 2005 3:28 PM

The following worked for me:

Dim Files() As String = Ftp1.ExpandRemoteFiles("/", True)
    Dim File As String
    For Each File In Files
      System.Diagnostics.Debug.WriteLine(File)
    Next

If it doesn't work for you, please email support@dart.com and supply the IP, Username and password you are using so we can test it here.

Reply | PowerTCP FTP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX