Solved

Software that Automatically Deletes files older than X days

Posted on 2012-03-12
9
109 Views
Last Modified: 2015-05-25
Can anyone recommend some good software that will delete files older than X days or that runs every month for shares on my server. If Microsoft had a tool that would be even better. Want to clear out some shares every month on our Server 2008.

Also looking some good quota management software for folders, i know Microsoft has management for drives but i need to apply it to a load of folders (users homes)

Thanks for any help.
0
Comment
Question by:Ricochet69
9 Comments
 

Expert Comment

by:Grawlix
ID: 37710787
You could use the following VBScript to accomplish this. You'll need to change the sRoot and NMaxFileAge variables to what you need and save it to .VBS. The create a task schedule job on the server with cscript.exe as the program and the path to the .vbs file as the arguments.

On Error Resume Next

Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")
sRoot = "C:\Path To Old Files"			'Path root to look for files
today = Date
nMaxFileAge = 3					'Files older than this (in days) will be deleted

DeleteFiles(sRoot)

Function DeleteFiles(ByVal sFolder)

	Set oFolder = oFileSys.GetFolder(sFolder)
	Set aFiles = oFolder.Files
	Set aSubFolders = oFolder.SubFolders

	For Each file in aFiles
		dFileCreated = FormatDateTime(file.DateCreated, "2")
		If DateDiff("d", dFileCreated, today) > nMaxFileAge Then
			file.Delete(True)
		End If
	Next

	For Each folder in aSubFolders
		DeleteFiles(folder.Path)
	Next

End Function

Open in new window

0
 
LVL 9

Expert Comment

by:AdrienneSperber
ID: 37710832
We create .bat files and then schedule them to run using windows task scheduler.
Here is a good reference for commands: http://ss64.com/nt/robocopy.html
0
 

Author Comment

by:Ricochet69
ID: 37714505
Id like to get some nice and easy to use GUI software if anyone could recommend some without using scripts and windows scheduler.
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Expert Comment

by:Grawlix
ID: 37715911
Here are a couple that will do what you are asking for in a gui.  Of course, the niceness of a programmed turnkey solution comes with a monetary cost.  ;)


File Automation Workshop

Win Quota
0
 

Author Comment

by:Ricochet69
ID: 37766479
Thanks Guys,

Currently testing these out will get back when i come to a solution
0
 

Author Comment

by:Ricochet69
ID: 37775435
I changed the vb script for just one day and i got the following error vbscript error
0
 

Accepted Solution

by:
Ricochet69 earned 0 total points
ID: 37801492
ok so the script didnt work. I used a different powershell script instead. This will remove both files and folders older than 15 days. Some of the code isnt needed. Ive also used file server resource manager for keeping quotas on files and folders.

#----- define parameters -----#
#----- get current date ----#

$Now = Get-Date

#----- define amount of days ----#

$Days = "1"

#----- define folder where files are located ----#

$TargetFolder = "C:\...yourtargetfolder"

#----- define extension ----#

$Extension = "*.log"

#----- define LastWriteTime parameter based on $Days ---#

$LastWrite = $Now.AddDays(-$Days)

 

#----- get files based on lastwrite filter and specified folder ---#

$Files = Get-Childitem $TargetFolder -Recurse -Force | Where {$_.LastWriteTime -le "$LastWrite" -and (! $_.PSIsContainer)}

 

foreach ($File in $Files)

    {

    if ($File -ne $NULL)

        {

        write-host "Deleting File $File" -ForegroundColor "DarkRed"

        Remove-Item $File.FullName -force | out-null

        }

    else

        {

        Write-Host "No more files to delete!" -foregroundcolor "Green"

        }

    }

$Folders = Get-Childitem $TargetFolder -Recurse | Where {$_.LastWriteTime -le "$LastWrite" -and ( $_.PSIsContainer)}

if ($Folders.Count -ge 1)
{
 [array]::Reverse($Folders)
}


foreach ($Folder in $Folders)

    {

    if ($Folder -ne $NULL)

        {
	 	 write-host "Deleting File $Folder" -ForegroundColor "DarkRed"
		 $children = Get-ChildItem -Recurse -Force -Path $Folder.FullName
	 
           if($children -eq $null)
   	   {
        	Remove-Item $Folder.FullName
    	   }
    	
	 $children = $null


        }

    else

        {

        Write-Host "No more files to delete!" -foregroundcolor "Green"

        }

    }

Open in new window

0
 
LVL 34

Expert Comment

by:Seth Simmons
ID: 40794654
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This is a fairly complicated script that will install the required prerequisites to install SCCM 2012 R2 on a server.  It was designed under the functional model in order to compartmentalize each step required, reducing the overall complexity.  The …
Know what services you can and cannot, should and should not combine on your server.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

810 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