SQLTeam.com | Weblogs | Forums

SQL Server Agent CmdExec command failed


Hi All,

I am working on purging task and need to delete files from different folders with different retention period. I want to use below statement

FORFILES /p "D:\SQL\MSSQLSERVER\Archive" -s -m . /d -5 /C "cmd /c Del /Q /F @FILE" && FORFILES /p "D:\SQL\MSSQLSERVER\Archive_user" -s -m . /d -30 /C "cmd /c Del /Q /F @FILE" && FORFILES /p "D:\SQL\MSSQLSERVER\Archive_Hr" -s -m . /d -90 /C "cmd /c Del /Q /F @FILE"

I am concatenating with && two statements but still it failed with error

Executed as user: Domain\User. ERROR: Invalid argument/option - '&&'. Type "FORFILES /?" for usage. Process Exit Code 1. The step failed.

Please advise...