Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
Option Explicit Sub macro() ' Local variables Dim objFSO Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objFolder Dim objFile Dim objSubFolder Dim objCheckFile Dim objCheckFolder Dim Flag Dim strFolder As String strFolder = "C:\Users\James\Downloads\Myfolder\" ' Acess the folder Set objFolder = objFSO.GetFolder(strFolder) ' Check each file in this folder For Each objFile In objFolder.Files ' If file is old enough delete it If DateDiff("h", objFile.DateCreated, Now()) >= 24 Then objFile.Delete True End If Next ' Now check all folders For Each objSubFolder In objFolder.Subfolders If DateDiff("h", objSubFolder.DateCreated, Now()) >= 24 Then ' Assume we can delete it Flag = "yes" ' Any new files that prevent deletion For Each objCheckFile In objSubFolder.Files If DateDiff("h", objCheckFile.DateCreated, Now()) < 24 Then Flag = "no" End If Next ' Any new folders that prevent deletion For Each objCheckFolder In objSubFolder.Folders If DateDiff("h", objCheckFolder.DateCreated, Now()) < 24 Then Flag = "no" End If Next ' Delete folder if no newer items found If Flag = "yes" Then objSubFolder.Delete True End If End If Next End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.