How do I delete a .txt file with TSQL, without using xp_cmdshell
17,314
Use SQL Server Agent CmdExec job step? This can run "del"...
http://msdn.microsoft.com/en-us/library/ms190264.aspx
In step 8 you'd have del c:\importpath\toasted.txt
Your comment to your question states you are running a "SQL job", so no need to overkill with CLR or sp_OA% solutions :-)
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I am trying to use TSQL to delete a .txt file at the end of a process. My restriction is that I cannot use xp_cmdshell. I had tried using the undocumented xp_delete_file but from what I can find it will only delete SQLServer native .ldf or .bak files. Is there another approach that can be used? I am running in SQL server 2008 R2.
-
Matthew over 13 yearsYour answer is better than mine :)
-
brian over 13 yearsYes good answer gbn, keep it simple. You could also do it in powershell: remove-item "c:\importpath\toasted.txt"
-
Admin over 13 yearsThanks gbn. That worked. It was the obvious answer under my nose that I was missing. I used the powershell remove step.