' Enumerate all available and ready drive(s)
For Each drvInfo As IO.DriveInfo In IO.DriveInfo.GetDrives
If drvInfo.IsReady Then
Select Case drvInfo.DriveType
Case IO.DriveType.Fixed
Dim aNode As TreeNode = New TreeNode
aNode.Text = IIf(drvInfo.VolumeLabel <> "", drvInfo.VolumeLabel, "Local Disk") & "(" & drvInfo.Name.Replace("\", "") & ")"
aNode.Tag = drvInfo.Name.Replace("\", "")
tvwFolders.Nodes.Add(aNode)
gatherSubDir(aNode, drvInfo.Name.Replace("\", ""))
Case IO.DriveType.Removable
Dim aNode As TreeNode = New TreeNode
aNode.Text = IIf(drvInfo.VolumeLabel <> "", drvInfo.VolumeLabel, "Removable Disk") & "(" & drvInfo.Name.Replace("\", "") & ")"
aNode.Tag = drvInfo.Name.Replace("\", "")
tvwFolders.Nodes.Add(aNode)
gatherSubDir(aNode, drvInfo.Name.Replace("\", ""))
End Select
End If
Next
Private Sub gatherSubDir(ByVal node As TreeNode, ByVal dirName As String)
Dim dInfo As IO.DirectoryInfo = New IO.DirectoryInfo(dirName)
For Each anInfo As IO.DirectoryInfo In dInfo.GetDirectories
Try
If Not anInfo.Attributes And IO.FileAttributes.Hidden Then
Dim aNode As TreeNode
aNode = New TreeNode
aNode.Text = anInfo.Name
aNode.Tag = anInfo.FullName
node.Nodes.Add(aNode)
gatherSubDir(aNode, anInfo.FullName)
End If
Catch ex As Exception
End Try
Next
End Sub
This is how I explore drive(s) and directories. I tried it by running directly under visual studio IDE. My final purpose is create a tool to find some similar file(s) on several directory, hopefully I can cut down some meaningless spaces used.
I'm sorry for my language, cause I'm originally an Indonesian.