Hey everyone ~
I have an issue that is just a driving me nuts. I know how to get all files in a folder including everything in all subfolders, but after it gets to about 5000 files or so it begins to slow down. Which is a problem when you are trying to get everything in "Program Files" or "Windows." Below is the code i use to get all the files.
Public Function FindFilePaths(ByVal strpath As String)
Dim strDir() As String
Dim filesize As String
Dim lngBytes As Long
strDir = System.IO.Directory.GetDir
ectories(s
trpath)
Dim enDir As System.Collections.IEnumer
ator
enDir = strDir.GetEnumerator
While enDir.MoveNext
Try
Dim strFiles() As String
strFiles = System.IO.Directory.GetFil
es(CStr(en
Dir.Curren
t))
Dim enFiles As System.Collections.IEnumer
ator
enFiles = strFiles.GetEnumerator
While enFiles.MoveNext
System.Windows.Forms.Appli
cation.DoE
vents()
'Console.WriteLine(CStr(en
Files.Curr
ent))
intFileCount += 1
lngBytes = FileLen(CStr(enFiles.Curre
nt))
ArrLstCopyQBytes.Add(lngBy
tes)
filesize = convertSize(lngBytes)
lngTOTBytes += lngBytes
'CONVERTSIZE turns the number of bytes into the appropriate converstion (KB,MB,GB)
lblTotSIZE.Text = convertSize(lngTOTBytes).T
oString
'FILLQUEUE FILLS AN ARRAYLIST OR A LISTVIEW CONTROL WITH THE SOURCE, DESTINATION, AND FILESIZE.
fillQueue(CStr(enFiles.Cur
rent), strDESTINATION, filesize)
filesize = ""
GC.Collect()
End While
Catch ex As Exception
lstStatus.Items.Add("Could
not read files in " & strpath)
Finally
GC.Collect()
End Try
Me.Update()
Call FindFilePaths(CStr(enDir.C
urrent))
End While
GC.Collect()
End Function
This works extremely well when there is a small list of files (fewer than 5000). But once it starts getting about 10000 or even 40000 (Which "Program Files" easily gets that high) it becomes way to slow. This is VB.NET 2003. Anyone have any ideas on how to speed this up, its really nerve racking how slow it becomes?
Fuzzy024~
Start Free Trial