1

I am executing xp_cmdshell from the SQL query editor to delete a file in a folder but getting a two rows as result; the first row contains a message "The system cannot find the file specified." and second row contains "NULL"

I have tried following commands :

EXEC xp_cmdshell 'DEL C:\Documents and Settings\Administrator\Desktop\rough folder\hi.txt'

EXEC xp_cmdshell 'DEL "C:\Documents and Settings\Administrator\Desktop\rough folder\hi.txt"'
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ajendra Prasad
  • 111
  • 1
  • 2
  • 7
  • 1
    Can't reproduce - it works just fine, deletes the file on the first run, and on the second run - of course! - complains (since the file has been deleted). What account does your SQL Server Mgmt Studio run under?? Most likely, that user account just isn't permitted to go delete stuff out of the administrator's desktop directory – marc_s Sep 15 '11 at 06:27
  • Hi marc_s after executing the command I checked the file and found it wasn't deleted. I think the second point is what I have to go through... Will soon try to check it out – Ajendra Prasad Sep 15 '11 at 06:55
  • 1
    I was looking around for a solution and I found SQL server powershell comes to rescue in case I want to delete etc. in Sql server file system...... :) – Ajendra Prasad Sep 15 '11 at 07:24
  • Makes **a lot more sense** than using `xp_cmdshell` - for sure! – marc_s Sep 15 '11 at 08:33
  • yes marc_s its really a cool way.... but xp_cmdshell may have a usability outside SQL enviorment. I'll keep trying to execute it, hope fully I will get some good result. :) – Ajendra Prasad Sep 15 '11 at 09:19

0 Answers0