In a file path (c:\Test\), I have an EXCEL file named as "SundayReport(WTD and MTD).xls"
I need to rename the file to "SundayReport_WTD_MTD).xls" using xp_cmdshell.
Kindly suggest me how to change the name.
The RENAME
dos-command would do. Type RENAME /?
in Windows command shell (cmd.exe), see how you should run the command.
Then format the command as you need it in an VARCHAR (eg @cmd
) and execute it as EXEC xp_cmdshell @cmd;
.
Eg
DECLARE @cmd VARCHAR(8000);
SET @cmd='RENAME "C:\Test\SundayReport(WTD and MTD).xls" "SundayReport_WTD_MTD).xls"';
EXEC xp_cmdshell @cmd;