I have been struggling with the following error for 2 days now ERROR: UNC paths (\\machine\share) are not supported.
and have finally come across something that got plenty of up-votes here.
The poster mentions using pushd
and popd
to map to a free drive letter. But I have absolutely no Idea how to do this. and quite frankly, i'm afraid I mess something up :(
How would I implement this pushd
& popd
into my SQL code:
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
I assume I would need to put it in the line where I am setting @cmd
.
Any help would be great,
Thanks so much