I have the following module that I delete old files based on how old they are:
Sub Main()
Dim First_Date As String = Date.Today.AddDays(-7)
Dim Archive_Files() As String = System.IO.Directory.GetFiles("C:\Turnover")
Dim Filtered As New ArrayList
For x As Integer = 0 To Archive_Files.Length - 1
If File.GetLastWriteTime(Archive_Files(x)) < First_Date Then
Filtered.Add(Archive_Files(x))
End If
Next
For Each Found_File As String In Filtered
System.IO.File.Delete(Found_File)
Next
End Sub
The files in the 'Turnover' directory are:
4_11_2005.html
4_12_2005.html
4_13_2005.html
4_14_2005.html
4_15_2005.html
4_16_2005.html
4_17_2005.html
4_18_2005.html
4_19_2005.html
4_20_2005.html
4_21_2005.html
4_22_2005.html
4_23_2005.html
4_24_2005.html
Turnover.html
Shortcut to Turnover.html
The module does what it's supposed to do, but it also deletes these two files:
Turnover.html
Shortcut to Turnover.html
Which I don't want deleted.
Sub Main()
Dim First_Date As String = Date.Today.AddDays(-7)
Dim Archive_Files() As String = System.IO.Directory.GetFiles("C:\Turnover")
Dim Filtered As New ArrayList
For x As Integer = 0 To Archive_Files.Length - 1
If File.GetLastWriteTime(Archive_Files(x)) < First_Date Then
Filtered.Add(Archive_Files(x))
End If
Next
For Each Found_File As String In Filtered
System.IO.File.Delete(Found_File)
Next
End Sub
The files in the 'Turnover' directory are:
4_11_2005.html
4_12_2005.html
4_13_2005.html
4_14_2005.html
4_15_2005.html
4_16_2005.html
4_17_2005.html
4_18_2005.html
4_19_2005.html
4_20_2005.html
4_21_2005.html
4_22_2005.html
4_23_2005.html
4_24_2005.html
Turnover.html
Shortcut to Turnover.html
The module does what it's supposed to do, but it also deletes these two files:
Turnover.html
Shortcut to Turnover.html
Which I don't want deleted.