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
 Other Forums
 Other Topics
 Batch File

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-07-19 : 11:31:18
Hi am trying to write a batch file to copy the file to a new location, that part is easy i have it done, but i want to rename the file with the file name and append the current date

Example Filename_190706.txt


I've tried both of these but they do not work

copy c:\somefolder\filename.txt d:\backupfolder\filename_%date:~4,2%_%date:~7,2%_%date:~10,4%.txt

ren filename filename%date:~6,4%%date:~3,2%%date:~0,2%.csv

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-19 : 11:44:31
What is the date format on your m/c?
The second would cope with dd/mm/yyyy

should it be
ren filename.csv ....

Are you in the correct folder?


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-07-19 : 11:53:15
The format is dd-mm-yy

These are example i found on the net.

i want the file to be name like Filename_190706.txt
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-19 : 12:03:08
ren filename.txt filename%date:~0,2%%date:~3,2%%date:~6,2%.txt

I usually end up creating the cath file from sql server or running the command using xp_cmdshell because the date format can be changed.



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2006-07-19 : 12:12:21
Thanks, for your help on this solution
Go to Top of Page
   

- Advertisement -