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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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

739 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