Guys,
I need help with a script where I can tell it to delete files older than 2 days (date modified) in a folder called "c:\backup".
I was able to find some similar codes (see below), but this codes goes and delete folders instead files.
TIA,
Tnt
------------------------------
Option Explicit
Const intDaysOld = 30
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder("C:\temp")
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
'WScript.Echo objSubFolder.DateLastModified
If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
WScript.Echo objSubFolder.DateLastModified
objSubFolder.Delete True
End If
Next
I need help with a script where I can tell it to delete files older than 2 days (date modified) in a folder called "c:\backup".
I was able to find some similar codes (see below), but this codes goes and delete folders instead files.
TIA,
Tnt
------------------------------
Option Explicit
Const intDaysOld = 30
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder("C:\temp")
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
'WScript.Echo objSubFolder.DateLastModified
If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
WScript.Echo objSubFolder.DateLastModified
objSubFolder.Delete True
End If
Next