Private Sub GetFiles(ByVal e As String, ByVal dg As DataGridView)
Dim path As String, i As Int32 = 0
ToolStripProgressBar1.Step = 1
' grow the tree
Me.TreeView1.BeginUpdate()
For i = 0 To theDrives.Length() - 1 ' array of all hard drives on the computer
Try
path = theDrives(i, 0).ToString()
If path <> "Nothing" Then
Me.TreeView1.Nodes.Add(path.ToString())
AddDirectoriesNFiles(Me.TreeView1.Nodes(0), path.ToString(), "*.ttf")
End If
Catch ex As Exception
End Try
Next
Me.TreeView1.EndUpdate()
End Sub
Private Sub AddDirectoriesNFiles(ByVal rootNode As TreeNode, ByVal dir As String, ByVal fileMatch As String)
Dim node As TreeNode
Dim theFile As String = ""
'Loop through each folder in the directory
For Each di As IO.DirectoryInfo In _
New IO.DirectoryInfo(dir).GetDirectories()
'Add a new node
node = New TreeNode(di.Name)
rootNode.Nodes.Add(node)
'If there are subfolders, then loop through them
Try
AddDirectoriesNFiles(node, di.FullName, fileMatch)
Catch
MessageBox.Show("Insufficient rights for the folder")
End Try
Next
For Each curFile As String In IO.Directory.GetFiles(dir, fileMatch)
ToolStripStatusLabel4.Text = curFile.ToString()
theFile = curFile.ToString()
curFile = curFile.Substring(curFile.LastIndexOf("\") + 1)
ToolStripProgressBar1.PerformStep()
If ToolStripProgressBar1.Value = 100 Then
ToolStripProgressBar1.Value = 1
End If
curFile = curFile.Substring(curFile.LastIndexOf("\") + 1)
rootNode.Nodes.Add(New TreeNode(curFile))
FilesCounted = FilesCounted + 1
ToolStripStatusLabel2.Text = FilesCounted.ToString()
Application.DoEvents()
Next curFile
End Sub
|