Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.
Dim fso, startFolder, OlderThanDate Set fso = CreateObject("Scripting.FileSystemObject") startFolder = "\\sadvnfs01\Scan-DVN\" ' folder to start deleting (subfolders will also be cleaned) OlderThanDate = DateAdd("d", -7, Date) ' 7 days (adjust as necessary) DeleteOldFiles startFolder, OlderThanDate Function DeleteOldFiles(folderName, BeforeDate) Dim folder, file, fileCollection, folderCollection, subFolder Set folder = fso.GetFolder(folderName) Set fileCollection = folder.Files For Each file In fileCollection If file.DateLastModified < BeforeDate Then fso.DeleteFile(file.Path) End If Next Set folderCollection = folder.SubFolders For Each subFolder In folderCollection DeleteOldFiles subFolder.Path, BeforeDate Next End Function
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.