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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cannot connect to server with remote dekstop connection 5 41
Subtraction v Hex2Dec in vbscript 6 30
NTP Servers 4 42
Remote desktop connection frequent connection lost 5 45
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Learn about cloud computing and its benefits for small business owners.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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