RSS

Delete Shared Folder and it's Files from SQL Script using xp_cmdShell Commands.

We can use Xp_cmdShell command to delete the shared path files.

Syntax:
EXEC XP_CMDSHELL 'del ""'

Example:

EXEC xp_cmdshell 'del "\\GBSRPABPRD01\AutomationInputOutputDetails\Email Notification\Output\PDF\1\1.pdf"'

Normally the xp_cmdshell command is not enabled with SQL Server. We need to enable with Admin rights (i.e., Sa Rights) using the below SQL script for enabling the Xp_cmdshell command.

---- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
---- To update the currently configured value for advanced options.
RECONFIGURE
GO
---- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
---- To update the currently configured value for this feature.
RECONFIGURE
GO

read comments Read User's Comments