How do I build an SMS installer package or *.cmd file that will look for files and delete them?

Posted on 2008-10-24
Last Modified: 2013-11-21
What I need is a script that will run on the network, know what today's date is, look at the date of files in a number of folder locations and delete the files that are 3 days old or more? I have 10 network locations:

\\ServerName\SharePoint\FolderName3  and so on....

Question by:RBrown1375

Accepted Solution

zabu99 earned 500 total points
ID: 22800261
Here is a .vbs version.
I think that a .cmd or .bat would work just as well.

Do you want a log of the files that you delete? I can toss that on there if you want.

Please let me know if you have any questions.
'This script looks for files and deletes them if they are too old (sounds sad)'

'this is used in case you don't have rights to a particular folder'

'it will just skip to the next one'

on error resume next

'Set your variables and constants

dtmToday = Date


Set objFSO = CreateObject("Scripting.FileSystemObject")

'*** Calls the subroutine ***'

'Make sure that there are no ending backslashes'

CheckFolder (objFSO.GetFolder("\\ServerName\SharePoint\FolderName1"))

CheckFolder (objFSO.GetFolder("\\ServerName\SharePoint\FolderName2"))

CheckFolder (objFSO.GetFolder("\\ServerName\SharePoint\FolderName3"))

CheckFolder (objFSO.GetFolder("\\ServerName\SharePoint\FolderName4"))

CheckFolder (objFSO.GetFolder("\\ServerName\SharePoint\FolderName5"))


Sub CheckFolder(objCurrentFolder)

	For Each objFile In objCurrentFolder.Files

		intDaysDifference = DateDiff("d", objFile.DateCreated, dtmToday)

		If intDaysDifference >= FILE_AGE_LIMIT Then


		End If


End Sub

Open in new window


Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip is around source server preparation. No migration is an easy migration, there is a…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now