CREATE TABLE #tempList
(Files VARCHAR(500))
INSERT INTO #tempList
EXEC MASTER..XP_CMDSHELL 'dir D:\Backup'
--Delete the file if it already exists
set @cmd = 'del ' + @FileLocation + @FileName
exec master..xp_cmdshell @cmd
Note: By default XP_CMDSHELL is turned off, to enable XP_CMDSHELL run the following on the database server…
-- We need to have this ON because xp_cmdshell is an advanced option.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured values for sp_configure
RECONFIGURE WITH OVERRIDE
GO
-- Now, enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured values for sp_configure
RECONFIGURE WITH OVERRIDE
GO
Comments