• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

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

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....

1 Solution
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now