Category: Script

Script: Delete files older then x days.

The other day I got a question if they could delete files in a folder older then 7 days automaticlly. I solved the question with a script and a scheduled task. And I thought id share the script with you. I would like to thank Fredrik Wall for script review.

‘This is a script to delete files older then specified days

Option Explicit

Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld

‘iDaysold = NumberofDays
iDaysOld = 7

‘sDirectoryPath = “Folder to deleteFiles in”
sDirectoryPath = “C:Tempforanexample”

On Error Resume Next

Set oFSO = CreateObject(“Scripting.FileSystemObject”)
If objFSO.FolderExists(sDirectoryPath) Then
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files

For each oFile in oFileCollection
If oFile.DateLastModified < (Date() – iDaysOld) Then
oFile.Delete(True)
End If
Next
else
WScript.Echo “No Folder”
End If

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing

Change sms client cache location with a script

If you would like to change the location of  the client cache on your client you can do this with the following scipt. Where D: is where you want to set the cache location. Change for your own usage.

On Error Resume Next
Set oUIResource = CreateObject(“UIResource.UIResourceMgr”)
Set objCacheInfo = oUIResource.GetCacheInfo
nValueToSet = “D:”
objCacheInfo.Location = nValueToSet

Note: It will create a folder ccmcache under the folder you select. The folder does not need to exist but the drive needs to exist. 

WordPress Themes