Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Rename Excel file in sql server or xp_cmdshell

Author  Topic 

cottage125
Starting Member

32 Posts

Posted - 2008-11-26 : 15:18:51
I want to rename one template using SSIS's Execute SQL task or using sql server commands
I need to put timestamp while renameing the original file so u can say i want
C:\abc\test_temp.xls file to be renamed as C:\abc\test_112620081400.xls
i can do that using batch file plz run first 3 lines as a batch file

for /f "tokens=2-4* delims=/ " %%a in ('DATE /T') do set THEDATE=%%c%%b%%a
Ren C:\abc\test_temp.xls test_%THEDATE%.xls
PAUSE

Then execute it works
----------------------------
BUT IF U RUN IT IN SQL using xp_cmdshell IT GIVES ERROR
rem DECLARE @rc int
rem Exec master..xp_cmdshell'for /f "tokens=2-4* delims=/ " %%a in ('DATE /T') do set THEDATE=%%c%%b%%a'
rem Exec master..xp_cmdshell'Ren C:\abc\test_temp.xls test_%THEDATE%.xls'

Error=
rem Msg 102, Level 15, State 1, Line 3
rem Incorrect syntax near 'DATE'.

so ultimately i want to rename a file using sql server.I want this as a part of one ssis package
which runs daily.
Any other new,creative solution to rename is welcomed.
Thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-11-26 : 17:40:51
you can use Filesystem task in SSIS to do this.
Go to Top of Page
   

- Advertisement -