| | |
Search for files within certain date range
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 9
Reputation:
Solved Threads: 0
I am new to VB and am trying to create a program that will search for files in a user specified directory within a specified date range, and then list the files in a list view. I've managed to figure most of it out except how to specify the date range I want.
Simplified a bit, this is what I have:
I want the search to produce all files that are older than 2 years, and maybe provide a field where the user can specify a date, and then the search would find all files older than the date they enter. Any help is greatly appreciated!
Simplified a bit, this is what I have:
VB.NET Syntax (Toggle Plain Text)
Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click Dim dirInfo As New DirectoryInfo(DirSearchTxtBox.Text) Dim CutOffDate As Date = Date.FromOADate(4 / 1 / 2008) FilesSearch(dirInfo, CutOffDate, FilesList) End Sub Public Sub FilesSearch(ByVal dirInfo As DirectoryInfo, ByVal CutOffDate As Date, ByVal List As ListView) Dim resultFiles() As FileInfo resultFiles = dirInfo.GetFiles(CutOffDate) For Each resultFile As FileInfo In resultFiles Dim colItem(5) As String Dim attributes As ListViewItem colItem(0) = (resultFile.Name) colItem(1) = (resultFile.DirectoryName) colItem(2) = (resultFile.LastAccessTime) colItem(3) = (resultFile.Length / 1000) colItem(4) = (resultFile.Attributes) attributes = New ListViewItem(colItem) FilesList.Items.Add(attributes) Next resultFile Dim SubDirs() As DirectoryInfo = dirInfo.GetDirectories() For Each SubDir As DirectoryInfo In SubDirs FilesSearch(SubDir, CutOffDate, List) Next SubDir End Sub
I want the search to produce all files that are older than 2 years, and maybe provide a field where the user can specify a date, and then the search would find all files older than the date they enter. Any help is greatly appreciated!
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
Try this:
Imports System.IO
Public Class Form1
Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
Dim dirInfo As New DirectoryInfo(DirSearchTxtBox.Text)
Dim CutOffDate As Date = "#6 / 1 / 2008#"
FilesSearch(dirInfo, CutOffDate, FilesList)
End Sub
Public Sub FilesSearch(ByVal dirInfo As DirectoryInfo, ByVal CutOffDate As Date, ByVal List As ListView)
Dim resultFiles() As FileInfo
resultFiles = dirInfo.GetFiles()
For Each resultFile As FileInfo In resultFiles
If resultFile.CreationTime.Date < CutOffDate Then
Dim colItem(5) As String
Dim attributes As ListViewItem
colItem(0) = (resultFile.Name)
colItem(1) = (resultFile.DirectoryName)
colItem(2) = (resultFile.LastAccessTime)
colItem(3) = (resultFile.Length / 1000)
colItem(4) = (resultFile.Attributes)
attributes = New ListViewItem(colItem)
FilesList.Items.Add(attributes)
End If
Next resultFile
Dim SubDirs() As DirectoryInfo = dirInfo.GetDirectories()
For Each SubDir As DirectoryInfo In SubDirs
FilesSearch(SubDir, CutOffDate, List)
Next SubDir
End Sub
End Class Last edited by waynespangler; Jun 18th, 2008 at 1:50 pm.
Wayne
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
![]() |
Similar Threads
- Help.. my hard drive suddenly run out of space (Viruses, Spyware and other Nasties)
- Internet Explorer-OUT OF ORDER + More (Viruses, Spyware and other Nasties)
- Fake Microsoft Windows Security Warning (Viruses, Spyware and other Nasties)
- help with removing Aurora virus---new victim (Viruses, Spyware and other Nasties)
- spyware has taken control of my pc (Viruses, Spyware and other Nasties)
- Aurora and more (Viruses, Spyware and other Nasties)
- Cool Web Search hijack (Viruses, Spyware and other Nasties)
- need help with aurora popups (Viruses, Spyware and other Nasties)
- When a host says "included scripts" (Networking Hardware Configuration)
Other Threads in the VB.NET Forum
- Previous Thread: Problem Displaying Items
- Next Thread: Syntax Error
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access arithmetic array assignment basic binary bing box button buttons center check code combobox component connectionstring convert cpu crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist editvb.net excel file-dialog firewall folder ftp google hardcopy image images isnumericfuntioncall login math memory mobile ms mssqlbackend mysql navigate net networking opacity output peertopeervideostreaming picturebox1 port print printpreview problemwithinstallation project record reports" reuse save savedialog searchbox serial soap storedprocedure string tcp temp text textbox timer toolbox trim updown useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf





