That undocumented xp_delete_file


I don’t know whether we should not use undocumented sp because it can stops working for reasons we dot know.

Anyway, here is the code snippet:


--Works with SQL Server 2012
--Does not work with SQL Server 2008 R2
DECLARE @DeletePriorThisDate datetime =DateAdd(day, -7, GetDate())

EXECUTE master.sys.xp_delete_file
0, -- FileTypeSelected (0 = FileBackup, 1 = FileReport)
N'C:\Backup\', -- folder path (trailing slash)
N'bak', -- file extension with no dot
 @DeletePriorThisDate,
1 -- subfolder flag 1 with,0 without

 

 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s