[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Software that Automatically Deletes files older than X days

Posted on 2012-03-12
9
Medium Priority
?
173 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
OfficeMate Freezes on login or does not load after login credentials are input.
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 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…
Suggested Courses

650 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