Using ListDirectory to display only directories not files

Advertisement

davefrag
Joined:
Posts:
3
Location:
Stamford, CT

Using ListDirectory to display only directories not files

I'm using vb.net code to open an SFTP session and list only directories, not files within directories. I have not yet been successful in creating a listing of only directories. I included the vb.net code below which should be putting only the names of directories in a listview container although I can't seem to get it to work. Any help is appreciated.

Dim directory
Dim fileInfo
directory = mySession.ListDirectory(ManageHosts.tbx_DestDirectory.Text)
Lbx_DestDirectory.Items.Clear()
With Lbx_DestDirectory
    For Each fileInfo In directory.Files
        If fileInfo.Name <> "." Or fileInfo.Name = "*." Then
            .Items.Add(fileInfo.Name)
        End If
    Next
End With

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
32,896
Location:
Prague, Czechia

Re: Using ListDirectory to display only directories not files

    For Each fileInfo In directory.Files
        If fileInfo.IsDirectory And (Not fileInfo.IsThisDirectory) Then
            .Items.Add(fileInfo.Name)
        End If
    Next

Reply with quote

Advertisement

You can post new topics in this forum