Dim oFs
Dim oFolder
Dim oFile
Dim Folder
Dim FolderSpec
Dim FileCollection
FolderSpec = "C:\testing"
Set oFs = CreateObject("Scripting.FileSystemObject")
If oFs.FolderExists(FolderSpec) Then
Set oFolder = oFs.GetFolder(FolderSpec)
Set FileCollection = oFolder.SubFolders
On Error Resume Next
For Each subfolders In FileCollection
For Each oFile In subfolders.Files
If DateDiff("d", FileDateTime(oFile), Now) >= 2 Then
oFile.Delete
End If
Next
Next
End If
The above coding is delete all the files, including the new created file.
Can anybody teach me how to delete the files, and subfolders which are more than 2 days only?
Dim oFolder
Dim oFile
Dim Folder
Dim FolderSpec
Dim FileCollection
FolderSpec = "C:\testing"
Set oFs = CreateObject("Scripting.FileSystemObject")
If oFs.FolderExists(FolderSpec) Then
Set oFolder = oFs.GetFolder(FolderSpec)
Set FileCollection = oFolder.SubFolders
On Error Resume Next
For Each subfolders In FileCollection
For Each oFile In subfolders.Files
If DateDiff("d", FileDateTime(oFile), Now) >= 2 Then
oFile.Delete
End If
Next
Next
End If
The above coding is delete all the files, including the new created file.
Can anybody teach me how to delete the files, and subfolders which are more than 2 days only?