Using xp_cmdshell to rename Files,Folder and Sub Folder using Sql

Exec master.dbo.xp_cmdshell 'rename C:\OldFileName.* NewFileName.*'
   
 Exec master.dbo.xp_cmdshell 'rename C:\MasterFolderName MasterFolderNewName'
   
 DECLARE @MasterFolder VARCHAR(15)
   
   
 DECLARE @query NVARCHAR(MAX)

 SET @MasterFolder = 'MasterFolder'   

 SET @query = 'exec master.dbo.xp_cmdshell ''rename C:\' + @MasterFolder
    + '\SubFolderName SubFolderNewName'''

 PRINT @query

 EXEC sp_executesql @query

Post a Comment

0 Comments