Robocopy log file and current date

Discussion in 'Scripting' started by David Allen, Feb 16, 2006.

  1. David Allen

    David Allen Guest

    I am using a .bat with robocopy
    ROBOCOPY.EXE <source> <dest> *.dwg /S /MIR /PURGE /log:Sync.log
    the batch runs every day at midnight
    I want a log file for each day.
    How can I do that?
    is there like a %date% variable?
     
    David Allen, Feb 16, 2006
    #1
    1. Advertisements

  2. David Allen

    Karsten H Guest

    Hi Dave,

    There is a %DATE% you can use, or a %NOW% if needed.
    DATE displays the date as formatted in the computers regional settings. NOW
    displays date and time.

    /Karsten
     
    Karsten H, Feb 16, 2006
    #2
    1. Advertisements

  3. In which environment is there a %NOW%? And beware that %DATE% often
    contains slashes, which make it unsuited for file names.

    I use 4NT's built-in variable %_ISODATE or, when finer granularity is
    required, %_DATETIME; these are documented at
    <http://jpsoft.com/help/_isodate.htm> and
    <http://jpsoft.com/help/_datetime.htm>. 4NT is a commercial product.

    A similar result can be achieved using CMD.EXE, but it's more
    complicated.

    Your command could look like this:
    ROBOCOPY <source> <dest> *.dwg /XO /MIR /log:%_DATETIME.log
    Note that the switches /S and /PURGE are redundant when you have /MIR. I
    also recommend using /XO to avoid copying the same unchanged files each
    time.
     
    Michael Bednarek, Feb 17, 2006
    #3
  4. David Allen

    David Allen Guest

    Thankx but is there any other solution without buying 4NT
    I think 4NT is overkill for this need
     
    David Allen, Feb 17, 2006
    #4
  5. David Allen

    i3inary Guest

    i put this at the top of all my batch files that i need to use date in.

    variable breakdown is as follows:
    month - %MM%
    day - %DD%
    century - %YC%
    year - %YY%

    :::::::::::::::::::::::::::::::::::::::::::::::::::::
    ::[][] find and parse the current environments date
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::
    @echo off
    if "%1"=="GoTo" goto %2
    echo e180 BF 07 01 B4 04 CD 1A E8 02 00 89 CA E8 00 00> %temp%.\t1.src
    echo e18F 86 D6 88 D0 D4 10 0D 30 30 86 C4 AB 47 C3>> %temp%.\t1.src
    for %%? in (rip 180 g w q) do echo %%?>> %temp%.\t1.src
    echo SET %%1=XX XX XX XX> %temp%.\t2.bat
    DEBUG %temp%.\t2.bat < %temp%.\t1.src > nul
    call %temp%.\t2.bat _
    %0 GoTo parse %_% MM DD YC YY
    :parse
    set %7=%3
    shift
    if not "%7"=="" goto parse
    for %%? in (t1.src t2.bat) do del %temp%.\%%?
    set _=
    :::::::::::::::::::::::::::::::::::::::::::::::::::::
    ::[][] example of setting variables with dates
    :::::::::::::::::::::::::::::::::::::::::::::::::::::
    set currentdate=%MM%%DD%%YC%%YY%
    set logfile=log_backup_%currentdate%_.log


    ultimately i forget where i got this snippet of code but supposedly this
    will work on any windows version up to 2k3...personally i know it works on
    xp,2k,2k3 just fine.
     
    i3inary, Mar 30, 2006
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.