0

I'm looking for a way to rename an XML file from another server.

I'm currently able to do this locally with the code below but now need to rename the file from a different server.

DECLARE @Rename NVARCHAR(2000)

SET @Rename = 'ren "D:\Example\ExampleFolderPath\' + @OriginalFileName + '"' + '  "RENAMED_FILE.xml"'

EXEC master..xp_cmdshell @Rename
Thom A
  • 88,727
  • 11
  • 45
  • 75
Theren
  • 43
  • 4
  • 3
    Honestly, why do you want to do this in T-SQL at all? SQL isn't a scripting language. You should be doing this in something that is designed to do such tasks, such as Powershell. – Thom A Feb 15 '22 at 16:05
  • Generally this is not recommended, but if you must. You need to use the UNC path for the folder path (something like "\\servername\path") or map the network drive to a letter on the machine where SQL Server is running, and then use that letter. Also need to ensure the service account has access. Assuming your using AD, you can use ```EXEC master..xp_cmdshell 'whoami'``` to figure out what account is being used to access the folder – Stephan Feb 15 '22 at 18:09

0 Answers0