SQL Server – Use T-SQL to delete files older than X days
Sometimes there is a need to delete backup files via tSQL. Here is a script that can do the trick.
— -d represents number of days, – 2 represents file older than 2 days set the parameter as needed
exec xp_CMDShell ‘Forfiles -p “C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA” -s -m *.trc -d -2 -c “Cmd /C del @FILE”‘
enjoy!
Comments
I take pleasure in, cause I discovered exactly what I used to be having
a look for. You have ended my four day long hunt! God Bless
you man. Have a nice day. Bye