Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Forfiles Utility Error When No Files to Delete Expand / Collapse
Author
Message
Posted Friday, May 10, 2013 7:01 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, April 12, 2014 11:40 AM
Points: 2,795, Visits: 8,297
I'm using the FORFILES utility to delete files from folders older than 'X' days.

forfiles /p "i:\objectscripts" /s /m *.* /c "cmd /c del @path" /d -120

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 ?



Post #1451566
Posted Monday, May 13, 2013 4:38 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 9:25 AM
Points: 7,070, Visits: 12,523
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

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1452355
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse