Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
Dim f, d As Integer
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim StrFiles As String
StrFiles = TextBox1.Text
SaveFileDialog1.Title = "Please Select a File"
SaveFileDialog1.InitialDirectory = "C:\Users\boscam\Documents"
SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.ShowDialog()
Using sw As StreamWriter = New StreamWriter(SaveFileDialog1.FileName) ', False, System.Text.Encoding.Unicode)
sw.WriteLine("Directory Path" & vbTab & "File Name" & vbTab & "Date Accessed")
f = 0
d = 0
sw.WriteLine(StrFiles)
Doit(StrFiles, sw)
End Using
RichTextBox1.Text = ("Search has completed and outputed to: " & SaveFileDialog1.FileName & vbCrLf _
& "Number of Directories searched: " & d & vbCrLf _
& "Number of Files searched: " & f)
End Sub
Private Sub Doit(ByVal startingDir As String, ByVal sw As StreamWriter)
Dim StartDI As New DirectoryInfo(startingDir)
Dim SubFI As FileInfo() = StartDI.GetFiles(TextBox3.Text)
Dim SubDI As DirectoryInfo() = StartDI.GetDirectories
'Dim S As Long = 0
' do files first
For Each SubFItemp In SubFI
If DateDiff(DateInterval.Day, SubFItemp.LastWriteTime, Now) > TextBox2.Text Then
'MsgBox(DateDiff(DateInterval.Day, SubFItemp.LastWriteTime, Now))
sw.WriteLine(vbTab & SubFItemp.Name & vbTab & SubFItemp.LastWriteTime & vbTab & (DateDiff(DateInterval.Day, SubFItemp.LastAccessTime, Now)))
'SubFItemp.Delete()
f = f + 1
End If
Next
' do the subdirectories, and then descend into the directory structure
For Each SubDITemp In SubDI
sw.WriteLine(SubDITemp.FullName & vbTab & vbTab & vbTab & d)
d = d + 1
' a recursive call to this routine
Doit(SubDITemp.FullName, sw)
Next
End Sub
End Class
|