xp_cmdshell

  • I'm try to use xp_cmdshell to delete a file using xp_cmdshell, it returns that it can't find the file. It appears that it staying in the c: directory.

    Should I have a call to put me on the "D" first or can I do it from any place (drive) as long as I give the full pathname.

    in the code @osd_cmd is made up of the directory, path & filename (i.e del D:\Program File\backup\FileA.bak)

    exec xp_cmdshell @OS_CMD

  • Try putting the path in double quotes:

    del "D:\Program File\backup\FileA.bak"

  • matt6288 (7/11/2013)


    Try putting the path in double quotes:

    del "D:\Program File\backup\FileA.bak"

    As Matt pointed out, double quotes are required when a space is in the path or filename. Allthough it's not required when there is no space in the patch/filename, it won't fail either. Therefor the best approach is to allways use double quotes.

    Also make sure the account used to execute XP_CMDSHELL has the correct permissions on the folder to delete the file(s). If you execute the command "WhoAmI.exe" throught the XP_CMDSHELL you can see what account is used.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply