patternMinor
Recursive filename search
Viewed 0 times
recursivefilenamesearch
Problem
I have created a little program to search a set of folders holding documents scanned.
The folder structure is as follows:
c:\images\year\month\date\documenttype\firstpartofdocumentNo.\
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:
I have a
The problem is it can take up to five minutes to se
The folder structure is as follows:
c:\images\year\month\date\documenttype\firstpartofdocumentNo.\
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
NextI 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 se
Solution
This might sound like a goofy answer, but if you already have Windows' file indexing service set up and running on your system, you can search the database contents of the index results using simple SQL terminology.
Here is an article that shows you how
In this way, you're not traversing the directory tree each time you search, but rather you're letting Windows Indexing Service log each new file when it is entered, and then searching the resulting database of information.
Here is an article that shows you how
In this way, you're not traversing the directory tree each time you search, but rather you're letting Windows Indexing Service log each new file when it is entered, and then searching the resulting database of information.
Context
StackExchange Code Review Q#81840, answer score: 2
Revisions (0)
No revisions yet.