Solved

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

Posted on 2008-10-24
2
397 Views
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\FolderName1
\\ServerName\SharePoint\FolderName2
\\ServerName\SharePoint\FolderName3  and so on....

0
Comment
Question by:RBrown1375
2 Comments
 
LVL 5

Accepted Solution

by:
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
FILE_AGE_LIMIT = 3
 
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"))
 
'Subroutine------------------'
Sub CheckFolder(objCurrentFolder)
	For Each objFile In objCurrentFolder.Files
		intDaysDifference = DateDiff("d", objFile.DateCreated, dtmToday)
		If intDaysDifference >= FILE_AGE_LIMIT Then
			objFSO.DeleteFile(objFile.path)
		End If
	Next
End Sub

Open in new window

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBScript on Html 15 47
Button function on table is in trouble 3 22
A Table within a User Form 24 46
Index Match Formula VBA 6 21
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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