Recursive Directory / File Listing With Progress?

  • Thread starter Daniel C. Di Vita
  • Start date
D

Daniel C. Di Vita

I am stating to write a small app that allows a user to catalog their
CD/dvd collection. I need some help, however. Here is some test code I
wrote for the recursive listing:

Imports System
Imports System.IO

Public Class MainClass
Dim AllText As String = ""
Shared Sub Main()
Dim nameOfDirectory As String = "C:\Documents and
Settings\divitdc\My Documents"

Dim myDirectory As DirectoryInfo
myDirectory = New DirectoryInfo(nameOfDirectory)
MainClass.AllText = MainClass.AllText &
My.Computer.FileSystem.GetFiles(nameOfDirectory).Count & vbCrLf
MainClass.Label1.Text = nameOfDirectory
MainClass.Label1.Visible = True
WorkWithDirectory(myDirectory)
MainClass.Label1.Visible = False
End Sub



Public Shared Sub WorkWithDirectory(ByVal aDir As DirectoryInfo)
Dim nextDir As DirectoryInfo
MainClass.Label1.Text = aDir.FullName.ToString
WorkWithFilesInDir(aDir)
For Each nextDir In aDir.GetDirectories
MainClass.Label1.Text = nextDir.FullName.ToString
WorkWithDirectory(nextDir)
Next
End Sub

Public Shared Sub WorkWithFilesInDir(ByVal aDir As DirectoryInfo)
Dim aFile As FileInfo
For Each aFile In aDir.GetFiles()
MainClass.AllText = MainClass.AllText & aFile.FullName &
vbCrLf
MainClass.RichTextBox1.Text = MainClass.AllText
Next

End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click

Main()

End Sub

End Class


So you click a button and it fills the textbox with the folders and
files.

My label never becomes visible or updates until the process is
finished. Why? How can I make it update in real-time?

Also if there are a lot of folders/ files the app tends to hang if I
try to click on it. It will run as long as I don't touch it.

How can I created a selection of just CD/DVD drives?

Any ideas on how to make this code more stable would be great. Thank
you.

Daniel
 
D

Daniel C. Di Vita

Ok, I found that using the .update command for the label and
richtextbox works great.
 
A

AMDRIT

If you are using 2.0 Framework, take a look at the BackgroundWorker Thread.
This control may simplify a lot of threading questions for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top