May 10, 2013 at 7:01 am
I'm using the FORFILES utility to delete files from folders older than 'X' days.
[font="Courier New"]forfiles /p "i:\objectscripts" /s /m *.* /c "cmd /c del @path" /d -120[/font]
I have it scheduled as a CmdExec type job on SQL 2005 (Server 2003). However, if there are no files to delete, the job fails with an error:
"ERROR: No files found with the specified search criteria. Process Exit Code 1. The step failed."
I'd rather not have the SQL job show as failed. Does anyone have an idea how to prevent failure ?
May 13, 2013 at 4:38 pm
One way would be to switch to PowerShell.
$path = '\\server\path'
$filter = '*.bak'
$retentionDate= (Get-Date).AddHours(-12)
#################################################
Get-ChildItem (Join-Path $path $filter) -Recurse |? {($_.PSIsContainer -eq $false) -and ($_.LastWriteTime -lt $retentionDate)} | Remove-Item -WhatIf
Just remove the -WhatIf from the code when you're ready for it to do work.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply