I have created a little program to search a set of folders holding documents scanned.
The folder structure is as follows:
the year folder contains years from 2005 - 2015
the month folder contains the months of the year (Obviously) same with date
the documenttype folder can contain between 1 and 5 folders
the firstpartofdocumentno. can contain between 1 and 3 folders
The code I am using at the moment is:
CompName = Environment.MachineName TicketNo = TxtTicketNo.Text If CompName = "Comp1" Then ImageDir = "C:\Images\" Else ImageDir = "\\Comp2\Images\" End If For Each DirYear As String In Directory.GetDirectories(ImageDir) Dim YearInfo As New DirectoryInfo(DirYear) For Each DirMonth As String In Directory.GetDirectories(DirYear) Dim MonthInfo As New DirectoryInfo(DirMonth) For Each DirDate As String In Directory.GetDirectories(DirMonth) Dim DateInfo As New DirectoryInfo(DirDate) For Each DirType As String In Directory.GetDirectories(DirDate) Dim TypeInfo As New DirectoryInfo(DirType) For Each DirStart As String In Directory.GetDirectories(DirType) Dim StartInfo As New DirectoryInfo(DirStart) MainDirectory = ImageDir & YearInfo.Name & "\" & MonthInfo.Name & "\" & DateInfo.Name & "\" & TypeInfo.Name & "\" & StartInfo.Name & "\" For Each Ticket As String In Directory.GetFiles(MainDirectory, TicketNo & "*") LstFiles.Items.Add(Ticket) Next Next Next Next Next Next
I have a
textbox on the form which is used to enter the last four numbers of the
ticketno and then this code runs when the button is clicked.
The problem is it can take up to five minutes to search, so I was wondering if there is a way to optimize this code to speed it up a bit or does this sound about right for searching that many folders.