?
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
Medium Priority
?
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
zabu99 earned 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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