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, July 26, 2014 8:10 PM
Points: 2,826, Visits: 8,463
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: Today @ 6:57 AM
Points: 7,084, Visits: 12,577
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
Post #1452355
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse