Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete files older than modified date 2

Status
Not open for further replies.

SQLWilts

Programmer
Feb 12, 2001
651
GB
I am hoping that someone will be able to help. I have a script that will delete files according to a date created, but refuses on a date modified with the error "Object does not support this property or method: 'srcFile.DateModified'. Can someone please tell me where I am going wrong, or rather what I can do to put it right! Here is the script:
/code
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

DeleteFilesa fso.GetFolder("D:\MyPath\TestDir")

Sub DeleteFilesa(srcFolder)

Dim srcFile

If srcFolder.Files.Count = 0 Then
Wscript.Echo "No File to Delete"
Exit Sub
End If

For Each srcFile in srcFolder.Files
If DateDiff("d", Now, srcFile.DateModified) < -7 Then
fso.DeleteFile srcFile, True
End If
Next

Wscript.Echo "Files Deleted successful"

End Sub
/code
 
try replacing:

Code:
 If DateDiff("d", Now, srcFile.DateModified) < -7 Then

with

Code:
 If DateDiff("d", Now, srcFile.DateLastModified) < -7 Then

Hope this helps.
 
Hi,
This script is great, I been trying to do a similar thing with the last access date using:
"If DateDiff("d", Now, srcFile.DateLastAccessed) < -7 Then"

I was wondering if you could help me take this script a bit further and check and delete sub directories and their contents if they haven’t been accessed by a certain amount of days. I would really appreciate your help.

Thanks in advance

Jt705
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top