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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

21 Experts available now in Live!

Get 1:1 Help Now