?
Solved

Software that Automatically Deletes files older than X days

Posted on 2012-03-12
9
Medium Priority
?
153 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
[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
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
Are your AD admin tools letting you down?

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 35

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

A safe way to clean winsxs folder from your windows server 2008 R2 editions
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 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