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 2000 Forums
 SQL Server Development (2000)
 How to change text souce filename?

Author  Topic 

TAS
Yak Posting Veteran

65 Posts

Posted - 2003-11-04 : 14:44:39
I need to import textfile from web everyday. File downloaded from web always has the same file name. I want it to be renamed by date. Anybody knows how to code that?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-04 : 15:06:52
You could use the RENAME DOS command. Something like this:

EXEC master.dbo.xp_cmdshell 'RENAME C:\temp\SomeFile.txt C:\temp\SomeFile' + CONVERT(VARCHAR(50), MONTH()) + CONVERT(VARCHAR(50), DAY()) + CONVERT(VARCHAR(50), YEAR()) + '.txt'


Tara
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-04 : 15:12:59
This one works:



DECLARE @SQL VARCHAR(8000)

SET @SQL = 'RENAME C:\temp\SomeFile.txt SomeFile' + CONVERT(VARCHAR(50), MONTH(GETDATE())) + CONVERT(VARCHAR(50), DAY(GETDATE())) + CONVERT(VARCHAR(50), YEAR(GETDATE())) + '.txt'

EXEC master.dbo.xp_cmdshell @SQL




Tara
Go to Top of Page
   

- Advertisement -