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
Solved

Software that Automatically Deletes files older than X days

Posted on 2012-03-12
9
118 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
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.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction: Sometimes when I receive a call from my users to solve their problems it is very difficult for me to found their computer IP address. Even finding their computer Host to provide remote support can be a problem.  So I resorted to Goo…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

839 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