Delete File(s) over a certain age

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi,

This is obviously a variation on a theme and I realise that the deleted
file(s) will not move to the recycle bin.

On the first business day of a new month ie March, I would like to delete
all the files in a specific folder which are more than a month old, ie from
Jan or before.

I already have a procedure which runs only on the first business day of each
month, so the additional code can be incoprorated into this.

Thanks for your help.

Regards
Richard
 
This is obviously a variation on a theme and I realise that the deleted
file(s) will not move to the recycle bin.

Okay, as long as you realize that the files will not be recoverable...
On the first business day of a new month ie March, I would like to delete
all the files in a specific folder which are more than a month old, ie
from
Jan or before.

I already have a procedure which runs only on the first business day of
each
month, so the additional code can be incoprorated into this.

TEST THE FOLLOWING AGAINST COPIES OF THE ACTUAL FILES FIRST to make sure it
works correctly!!!

' Put these with the rest of your Dim statements
Dim Path As String
Dim FileName As String
' ....
' ....
' Note the trailing backslash... always include it.
Path = "C:\TEMP\Test\"
FileName = Dir$(Path & "*.*")
Do While Len(FileName) > 0
If DateDiff("m", FileDateTime(Path & FileName), #3/1/2008#) > 1 Then
Kill Path & FileName
End If
FileName = Dir$
Loop

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top