By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,375 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,375 IT Pros & Developers. It's quick & easy.

batch file script

100+
P: 147
Hi,
my batch file named cpf.bat

Expand|Select|Wrap|Line Numbers
  1.      COPY C:\Progra~1\Micros~1\MSSQL\BACKUP\acaddb.bak F:\DATABACKUP\acaddb.bak
  2.  
Its working fine.

But in this ,i should append current date
.please help me ? how i should append current date with the filename while copying into my F drive.


Thanks in advance.................
Jan 6 '10 #1
Share this Question
Share on Google+
8 Replies


RedSon
Expert 5K+
P: 5,000
you can do something like

set MONTH=%date:~4,2%
set DAY=%date:~7,2%

and then use MONTH and DAY in your file path. Or you can just use %date%. Try echo %date% and see what it gives you.
Jan 6 '10 #2

100+
P: 147
hi,

now, i am changing my batch file script as now :

COPY C:\Progra~1\Micros~1\MSSQL\BACKUP\acaddb.bak F:\DATABACKUP\acaddb%date:~4,2%-%date:~7,2%-%date:~10%.bak
now my batch file is not running .......please help me out.
Jan 7 '10 #3

RedSon
Expert 5K+
P: 5,000
if you do "echo %date%" in your command window what happens?

Instead of calling date, assign it to a variable like I showed you.
Jan 7 '10 #4

100+
P: 147
hi,
what you have told according to that i have changed my batch file like this:

set val=echo %date%
COPY C:\Progra~1\Micros~1\MSSQL\BACKUP\acaddb.bak F:\DATABACKUP\acaddb%val.bak


my file is copying in the F drive ....but under the name like "acaddbval".........date is not getting append to the "acaddb" ......
Jan 7 '10 #5

Banfa
Expert Mod 5K+
P: 8,916
You have missed the ending % from %val%
Jan 7 '10 #6

100+
P: 147
hi,

i tried that too also......if i add % at the end of the variable.......script not at all running......(ie not copying from C drive to F drive).please help me out
Jan 7 '10 #7

Banfa
Expert Mod 5K+
P: 8,916
set val=echo %date%

should be

set val=%date%
Jan 7 '10 #8

100+
P: 147
hi,
what you told,i have tried like this also...but its useless.
Jan 8 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.