vbMarkO
asked on
ListBox1 Display Directory Folders .... ListBox2 Display files of ListBox1.SelectedItem
Been a while since I have done this but this is essentially what I need
1. ListBox1 will display all the Folders in specified Directory .......
2. ListBox2 will display all the files of what ever Folder is the Selected Item of ListBox1
I am using Visual Basic 2008 Express .....
1. ListBox1 will display all the Folders in specified Directory .......
2. ListBox2 will display all the files of what ever Folder is the Selected Item of ListBox1
I am using Visual Basic 2008 Express .....
2) ANSWER.
Dim oDirInfo As DirectoryInfo = Nothing
Dim oFileInfo() As FileInfo = Nothing
'Reading Directory Information
oDirInfo = New DirectoryInfo(ListBox1.Sel ectedItem. ToString)
oFileInfo = oDirInfo.GetFiles("*.*??")
If oFileInfo.Length > 0 Then
For idx As Integer = 0 To oFileInfo.Length - 1
ListBox2.Items.Add(oFileIn fo(idx).Fu llName)
Next
End If
Dim oDirInfo As DirectoryInfo = Nothing
Dim oFileInfo() As FileInfo = Nothing
'Reading Directory Information
oDirInfo = New DirectoryInfo(ListBox1.Sel
oFileInfo = oDirInfo.GetFiles("*.*??")
If oFileInfo.Length > 0 Then
For idx As Integer = 0 To oFileInfo.Length - 1
ListBox2.Items.Add(oFileIn
Next
End If
imports namespace
Imports System.IO
Imports System.IO
write 2nd one in listboxindexchanged event
Private Sub ListBox1_SelectedIndexChan ged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChan ged
ListBox2.Items.Clear()
Dim oDirInfo As DirectoryInfo = Nothing
Dim oFileInfo() As FileInfo = Nothing
'Reading Directory Information
oDirInfo = New DirectoryInfo(ListBox1.Sel ectedItem. ToString)
oFileInfo = oDirInfo.GetFiles("*.*??")
If oFileInfo.Length > 0 Then
For idx As Integer = 0 To oFileInfo.Length - 1
ListBox2.Items.Add(oFileIn fo(idx).Fu llName)
Next
End If
End Sub
Private Sub ListBox1_SelectedIndexChan
ListBox2.Items.Clear()
Dim oDirInfo As DirectoryInfo = Nothing
Dim oFileInfo() As FileInfo = Nothing
'Reading Directory Information
oDirInfo = New DirectoryInfo(ListBox1.Sel
oFileInfo = oDirInfo.GetFiles("*.*??")
If oFileInfo.Length > 0 Then
For idx As Integer = 0 To oFileInfo.Length - 1
ListBox2.Items.Add(oFileIn
Next
End If
End Sub
ASKER
Sorry I havent got back to you sooner ... ok these look right ... I will give them a go and get back to you as to the results.
vbMarkO
vbMarkO
ASKER
Gave these a try .... question the first one .... is it supposed to return and display in the lstFolders the full path?
If so ... then this wont work .... I need only th folder name ...
So, I did this and it gives me just the Folder Name
For Each Dir As IO.DirectoryInfo In _
New IO.DirectoryInfo(dirPath). GetDirecto ries
lstFolders.Items.Add(Dir)
Next
but havnt figured out yet how to get the files ...
I couldnt make the 2nd work because in lstFoldrs all I have is a Folder name not a full path ...
If thats not supposed to happen .. I will go at it again
If so ... then this wont work .... I need only th folder name ...
So, I did this and it gives me just the Folder Name
For Each Dir As IO.DirectoryInfo In _
New IO.DirectoryInfo(dirPath).
lstFolders.Items.Add(Dir)
Next
but havnt figured out yet how to get the files ...
I couldnt make the 2nd work because in lstFoldrs all I have is a Folder name not a full path ...
If thats not supposed to happen .. I will go at it again
ASKER
Ok it sort o works now .... but need help here
Dim newPath As String = dirPath & "\" & lstFolders.SelectedItem ' I get an error i I try to concatenate the
' path into a string variable then use that ... it wont work ... WHY?
'////////////////////// BELOW cod worked just fine ..... but this is just not applicable in my app
Dim folderInfo As New IO.DirectoryInfo("C:\Docum ents and Settings\Mark\My Documents\Visual Studio 2008\Projects\Code Library\Code Library\Code Library\Misc Code")
Dim newPath As String = dirPath & "\" & lstFolders.SelectedItem ' I get an error i I try to concatenate the
' path into a string variable then use that ... it wont work ... WHY?
'////////////////////// BELOW cod worked just fine ..... but this is just not applicable in my app
Dim folderInfo As New IO.DirectoryInfo("C:\Docum
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim strDirs() As String = Nothing
Dim msAppFolders As String = "C:\vssCarpenter\"
strDirs = Directory.GetDirectories(m
For Each myfolder As String In strDirs
ListBox1.Items.Add(myfolde
Next