Solved

Software that Automatically Deletes files older than X days

Posted on 2012-03-12
9
76 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
Comment Utility
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
Comment Utility
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
Comment Utility
Id like to get some nice and easy to use GUI software if anyone could recommend some without using scripts and windows scheduler.
0
 

Expert Comment

by:Grawlix
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Ricochet69
Comment Utility
Thanks Guys,

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

Author Comment

by:Ricochet69
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was supporting a handful of Windows 2008 (non-R2) 2 node clusters with shared quorum disks. Some had SQL 2008 installed and some were just a vendor application that we supported. For the purposes of this article it doesn’t really matter which so w…
Experts-Exchange users below are the steps you can follow to upgrade your Lync server to latest CU's or cumulative updates. Note: Perform it during non-production hours.   Step 1: Backup your lync and SQL server database. Follow below article: h…
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 the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now