Last active
July 25, 2019 14:17
-
-
Save Grimthorr/2dfdeb2e238b1b331264 to your computer and use it in GitHub Desktop.
A Visual Basic script to delete files from the specified folder that are older than the specified number of days.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Error Resume Next | |
'Dim some stuffs | |
Dim objFso, objFolder, objFile, strFolderPath, intDaysOlderThan | |
Set objFso = CreateObject("Scripting.FileSystemObject") | |
'Change these variables | |
strFolderPath = "C:\Temp" | |
intDaysOlderThan = 28 | |
'Do the magic | |
Call DeleteFiles(strFolderPath, intDaysOlderThan) | |
'Procedures | |
Sub DeleteFiles(path, days) | |
Set objFolder = objFso.GetFolder(path) | |
For Each objFile In objFolder.Files | |
If objFile.DateLastModified < (Now() - days) Then | |
objFile.Delete(True) | |
End If | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment