I am in need of a program or script that will allow me to delete files within a folder after a certain date. Can anyone direct me in how to do this. I am fairly new to VB.
This may not be exactly what you are looking for but you can follow the same idea to accomplish your task.
FYI this is done in VB.Net.....
Dim dInfo As DirectoryInfo = New DirectoryInfo("The path to your folder")
Dim NumOfDays as Integer = Some Integer
'Function that deletes files from the folder after X amount of days
Public Sub deleteAfterDays(ByVal d As DirectoryInfo, ByVal days As Integer)
Dim ts As TimeSpan
For Each f As FileInfo In d.GetFiles
ts.Subtract(f.CreationTime - Date.Now)
If ts.TotalDays > days Then
f.Delete()
End If
Next
End Sub
When you call the function, you pass in the two variables as parameters. ex: deleteAfterDays(dInfo, NumOfDays)
Note: You may not want to delete files that you modify frequently. In that case replace f.CreationTime with f.LastWriteTime. f.LastWriteTime will get the date the file was last modified, while f.CreationTime will get you the date the file was created.
"Cowards die many times before their deaths, The valiant never taste of death but once." - Julius Caesar
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.