SQL - Rename a file

Last Post 18 May 2011 09:17 AM by JASBRYDEN. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
JASBRYDEN
New Member
New Member

--
18 May 2011 07:05 AM
Hi

I am having a problem with this script that I have to rename a file with the date at the end of it. When I run the program it is deleting the file. Any ideas what I have wrong?


DECLARE
@TodayDate as varchar(40),
@TodayHour as varchar(40),
 @TodayMinu as varchar(40),
@NewFileName as varchar(100),
@cmdstr as varchar(128)
SELECT @TodayDate = CONVERT(VARCHAR(8), GETDATE(),112)
SELECT @NewFileName = 'Write-Off_Reports' + @TodayDate + '.xls'
print @NewFileName
set @cmdstr= 'move /Y "D:\HighJump Reports\Write-Off Reports\Write-Off_Reports.xls" "D:\HighJump Reports\Write-Off Reports\ "'+ @NewFileName
print @cmdstr EXEC master..xp_cmdshell @cmdstr
rm
New Member
New Member

--
18 May 2011 09:10 AM
Try this:
DECLARE
@TodayDate as varchar(40),
@TodayHour as varchar(40),
@TodayMinu as varchar(40),
@NewFileName as varchar(100),
@cmdstr as varchar(256)
SELECT @TodayDate = CONVERT(VARCHAR(8), GETDATE(),112)
SELECT @NewFileName = 'Write-Off_Reports' + @TodayDate + '.xls'
print @NewFileName
set @cmdstr= 'move /Y "D:\HighJump Reports\Write-Off Reports\Write-Off_Reports.xls" "D:\HighJump Reports\Write-Off Reports\' + @NewFileName + '"'
print @cmdstr EXEC master..xp_cmdshell @cmdstr
JASBRYDEN
New Member
New Member

--
18 May 2011 09:17 AM
Great thanks !!!
You are not authorized to post a reply.

Acceptable Use Policy