description-KILL-02-dec-2010.mp3
description-KILL-28-dec-2010.mp3
description-KILL-1-jan-2011.mp3
Now what I have so far:
Expand|Select|Wrap|Line Numbers
- Imports System.Text.RegularExpressions
- Imports System.IO
- Public Class Form1
- Dim pattern As String = "(\d?\d \w\w\w \d{4})\.\w{3}$"
- Sub Main()
- DeleteOldFiles("C:\test")
- End Sub
- Private Sub DeleteOldFiles(ByVal path As String)
- Dim filterRegex As New Regex(pattern)
- For Each filePath As String In Directory.EnumerateFiles(path)
- Dim match As Match = filterRegex.Match(filePath)
- If match.Success Then
- ' Convert the text into a date
- Dim dateString As String = match.Groups(2).Value
- Dim killDate As DateTime
- ' Note that if dates have a leading 0 like 01 nov 2010 you'll need "dd MMM yyyy".
- If DateTime.TryParseExact(dateString, "dd MMM yyyy", Nothing, Globalization.DateTimeStyles.None, killDate) Then
- If killDate < DateTime.Now Then
- File.Delete(filePath)
- Console.WriteLine("Deleting {0}...", filePath)
- End If
- End If
- End If
- Next
- MsgBox(DateString)
- MsgBox(DateTime.Now)
- MsgBox(path)
- MsgBox(DateString)
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- MsgBox(DateString)
- MsgBox(DateTime.Now)
- MsgBox(DateString)
- Call DeleteOldFiles("C:\test")
- End Sub
- Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
- MsgBox("You can't change this.")
- End Sub
- Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
- End Sub
- End Class
I was getting a few errors, now I am mysteriously not before I want to post this, one of them was:
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll
But my main problem is that we got the right file path detected, all the variables are reading correct, but the actual deleting process doesn't work. Help!?
I am just getting back into VB with a few years of hiatus, so forgive me if something looks stupid.
I am using VB 2010.
Here is a download link for the entire project so you can better assist me:
http://www.woofiles.com/dl-214353-796CAP07-DeleteOLDPsa.zip
or it's attached as well.