|
-
November 12th, 2019, 04:43 AM
#1
GetDirectories mistakenly returns [Documents and Settings] in Visual Studio 2012
I have a project I am working on for a friend.
The project contains a form with:
1 - ListBox (named "drivesList")
1 - ListBox (named "fileList")
1 - TreeView (named "TreeView1")
Here is my code:
Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
fileList.Items.Clear()
For Each di As IO.DriveInfo In DriveInfo.GetDrives
drivesList.Items.Add(di)
Next
End Sub
Private Sub drivesList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drivesList.SelectedIndexChanged
TreeView1.Nodes.Clear()
Try
Dim drive As DriveInfo = DirectCast(drivesList.SelectedItem, DriveInfo)
fileList.Items.Clear()
For Each file As String In IO.Directory.GetFiles(drive.Name)
If file.Contains(drive.Name) Then file = file.Replace(drive.Name, "")
fileList.Items.Add(file)
Next
For Each dirinfo As DirectoryInfo In drive.RootDirectory.GetDirectories()
Dim dirnode = New TreeNode(dirinfo.Name)
Dim tmpPath As String = dirinfo.FullName.ToString
Dim dc As Integer = Directory.GetDirectories(tmpPath).Count
TreeView1.Nodes.Add(dirnode)
If dc <> 0 Then
' add a blank "b" node so that a '+' appears before the parent node
dirnode.Nodes.Add("b")
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
As you can see, when the form loads, the drivesList gets populated with all of the drives it can properly access.
When I click on a drive (ie: C:\) the SelectedIndexChanged event begins to add all of the directories of the selected drive.
With respect to this drive, I have 10 directories on the C:\ drive (see image). None of them are {Documents and Settings} but my code keeps trying to add this folder. Can someone please tell me why?
C drive.jpg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|