1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Date variable in batch file

Discussion in 'Legacy Windows' started by Grunty, 2003/03/20.

Thread Status:
Not open for further replies.
  1. 2003/03/20
    Grunty

    Grunty Inactive Thread Starter

    Joined:
    2002/11/07
    Messages:
    326
    Likes Received:
    0
    I am writing a batch file to copy some files and directories to another drive once a day for backup purposes.

    Because the destination will hold several days backups, I would like to include a Make Directory command that will make a folder based on the date i.e. MD e:\backup folder\%todays_date% and then copy everything to that.

    Could anyone tell me the name of the variable, if there is one, or suggest another way of creating a folder from a batch file ,with a different name?

    Thanks
     
  2. 2003/03/20
    WhitPhil

    WhitPhil Inactive

    Joined:
    2002/01/07
    Messages:
    599
    Likes Received:
    4
    This should do what you want.

    echo.|date|find "Current" >cu##ent.bat
    echo set date=%%4> current.bat
    call cu##ent.bat
    del cu??ent.bat > nul
    mkdir d:\%date%

    (** "stolen" from somewhere. Apologies to author)
     

  3. to hide this advert.

  4. 2003/03/20
    Steve R Jones

    Steve R Jones SuperGeek Staff

    Joined:
    2001/12/30
    Messages:
    12,285
    Likes Received:
    249
    Darn Phil. I was getting real impressed till I found out you're a thief:D

    Might have to copy that one myself.
     
  5. 2003/03/20
    WhitPhil

    WhitPhil Inactive

    Joined:
    2002/01/07
    Messages:
    599
    Likes Received:
    4
    LOL

    There are sometimes that I see "neat" solutions, copy them but forget to note where and who I "stole" it from.
     
  6. 2003/03/21
    Grunty

    Grunty Inactive Thread Starter

    Joined:
    2002/11/07
    Messages:
    326
    Likes Received:
    0
    Many Thanks for the reply. The date generating bit of the script worked ok, but when it comes to "md e:\%date%" it falls over because the date format is 23/3/03. DOS thinks these are switches which are of course invalid.

    It is not as urgent now, as it turns out that the files I am backing up are 70Mb and the disc is zip drive of 100mb so I can only fit one day's worth on anyway

    Thanks again.
     
  7. 2003/03/21
    merlin

    merlin Inactive

    Joined:
    2003/01/07
    Messages:
    1,111
    Likes Received:
    0
    Winrar has some useful parameters to do these things.
    regards
     
  8. 2003/03/21
    WhitPhil

    WhitPhil Inactive

    Joined:
    2002/01/07
    Messages:
    599
    Likes Received:
    4
    "when it comes to "md e:\%date%" it falls over because the date format is 23/3/03 "

    Interesting!!

    On my PC, the date is returned as 03-21-2003. (Dashes instead of slashes).

    This must be a bios setting ??, since it occurs in real DOS also.
     
  9. 2003/03/21
    Grunty

    Grunty Inactive Thread Starter

    Joined:
    2002/11/07
    Messages:
    326
    Likes Received:
    0
    Of course, I should have thought of that - easy to change too.

    Thanks
     
  10. 2003/03/21
    WhitPhil

    WhitPhil Inactive

    Joined:
    2002/01/07
    Messages:
    599
    Likes Received:
    4
    Last edited: 2003/03/21
  11. 2003/03/21
    Grunty

    Grunty Inactive Thread Starter

    Joined:
    2002/11/07
    Messages:
    326
    Likes Received:
    0
    It;s OK, it is all in the date separator in the Ctrl Panel/Regional Settings.

    I am UK settings, changed it to "-" and I now have a folder called "Fri 23-03-2003 "

    I had to put quotes either side of %date% in the last line because of the spaces in the variable result.

    At least it all works now and as you borrowed it from somewhere else, I can claim all the credit and get lots of brownie points from my bosses - probably no end of year bonuses though.

    Thanks again for your help
     
  12. 2003/03/21
    WhitPhil

    WhitPhil Inactive

    Joined:
    2002/01/07
    Messages:
    599
    Likes Received:
    4
    Interesting again.

    My regional settings have a slash in them, and both a DOS windows and a restart to DOS result in the batch file working fine, and with dashes.

    Did you try the file in "real" DOS. The regional settings are Windows related and thus should not have any affect!

    I guess it really doesn't matter as long as what you have works, and it will always be done in a DOS window. (twas just out of interest).
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.