Need to rename a .txt file saved in a folder within a Mapped drive

Need to rename a .txt file saved in a folder within a Mapped drive

Examble ,

DECLARE @cmd varchar(2000)
DECLARE @C_Date Date = getdate()
Declare @DateasText as varchar(100) = @C_Date

SET @cmd = 'rename \Server1\Folder\Text.txt Text'+@DateasText+'.txt'
EXEC master..xp_cmdshell @cmd


  1. i get the below error
  • output
  • The syntax of the command is incorrect.