batch file script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santhanalakshmi
    New Member
    • May 2009
    • 147

    batch file script

    Hi,
    my batch file named cpf.bat

    Code:
     [B]    COPY C:\Progra~1\Micros~1\MSSQL\BACKUP\acaddb.bak F:\DATABACKUP\acaddb.bak[/B]
    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........ .........
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    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.

    Comment

    • santhanalakshmi
      New Member
      • May 2009
      • 147

      #3
      hi,

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

      COPY C:\Progra~1\Mic ros~1\MSSQL\BAC KUP\acaddb.bak F:\DATABACKUP\a caddb%date:~4,2 %-%date:~7,2%-%date:~10%.bak
      now my batch file is not running .......please help me out.

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        if you do "echo %date%" in your command window what happens?

        Instead of calling date, assign it to a variable like I showed you.

        Comment

        • santhanalakshmi
          New Member
          • May 2009
          • 147

          #5
          hi,
          what you have told according to that i have changed my batch file like this:

          set val=echo %date%
          COPY C:\Progra~1\Mic ros~1\MSSQL\BAC KUP\acaddb.bak F:\DATABACKUP\a caddb%val.bak


          my file is copying in the F drive ....but under the name like "acaddbval".... .....date is not getting append to the "acaddb" ......

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            You have missed the ending % from %val%

            Comment

            • santhanalakshmi
              New Member
              • May 2009
              • 147

              #7
              hi,

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

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                set val=echo %date%

                should be

                set val=%date%

                Comment

                • santhanalakshmi
                  New Member
                  • May 2009
                  • 147

                  #9
                  hi,
                  what you told,i have tried like this also...but its useless.

                  Comment

                  Working...