我一直在努力解决以下错误2天ERROR: UNC paths (\\machine\share) are not supported.
并且终于遇到了一些有很多上升选票here。
海报提到使用pushd
和popd
映射到免费的驱动器号。但我完全不知道如何做到这一点。而坦率地说,我害怕搞砸了一些事情:(
我将如何实施此pushd
& popd
到我的SQL代码中:
DECLARE @N AS VARCHAR(2) -- days for retention
DECLARE @path AS VARCHAR(128) -- the path for deletion
DECLARE @cmd AS VARCHAR(512) -- the actual command
SET @N = '7' -- change the days here (Deleting files which are older that @N days)
SET @path = '\\TOMANYMS\c$\JohnDoe\91\TEST\serverapps\export' -- Path of the files you would like to check
SET @cmd = 'FORFILES /P "' + @path + '" /S /M export_status.* /D -' + @N + ' /C "cmd /c del @PATH"' --Deletes on the export_status files older than 7 days.
EXEC master.dbo.xp_cmdshell @cmd
我认为我需要将其放在我设置@cmd
的行中。
任何帮助都会很棒,
非常感谢
答案 0 :(得分:1)
您可以使用&链接DOS命令。像这样的运算符:
set @cmd = 'pushd '+ @path+ ' & FORFILES /P \ /S /M export_status.* /D -' + @N + ' /C "cmd /c del @PATH"'+' & popd'