Redirecting Output to datestamped log. - Windows NT

This is a discussion on Redirecting Output to datestamped log. - Windows NT ; Hi Folks, Anyone know how to redirect output to a Datestamped file.... ie.. dir >> {date/t}.log Looks like it should be simple enough, but I've been looking thru posts, etc for a day now, and no soln yet. Thanks Danny...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Redirecting Output to datestamped log.

  1. Redirecting Output to datestamped log.

    Hi Folks,

    Anyone know how to redirect output to a Datestamped file.... ie..

    dir >> {date/t}.log

    Looks like it should be simple enough, but I've been looking thru
    posts, etc for a day now, and no soln yet.

    Thanks
    Danny

  2. Re: Redirecting Output to datestamped log.


    "DannyC" wrote in message
    news:4ee2d4a6.0405100513.436d7ba0@posting.google.c om...
    > Hi Folks,
    >
    > Anyone know how to redirect output to a Datestamped file.... ie..
    >
    > dir >> {date/t}.log
    >
    > Looks like it should be simple enough, but I've been looking thru
    > posts, etc for a day now, and no soln yet.
    >
    > Thanks
    > Danny


    You were probably looking in the wrong areas - it's a VFAQ
    in batch file news groups. Here is a solution:

    @echo off
    for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do set
    DateCode=%%a%%b%%c
    (unwrap line)

    When I type echo %date% at a Command prompt then I get this: Tue
    11/05/2004
    You may have to adjust the batch file to reflect your own date format.



  3. Re: Redirecting Output to datestamped log.

    "Pegasus \(MVP\)" wrote in message news:...
    > "DannyC" wrote in message
    > news:4ee2d4a6.0405100513.436d7ba0@posting.google.c om...
    > > Hi Folks,
    > >
    > > Anyone know how to redirect output to a Datestamped file.... ie..
    > >
    > > dir >> {date/t}.log
    > >
    > > Looks like it should be simple enough, but I've been looking thru
    > > posts, etc for a day now, and no soln yet.
    > >
    > > Thanks
    > > Danny

    >
    > You were probably looking in the wrong areas - it's a VFAQ
    > in batch file news groups. Here is a solution:
    >
    > @echo off
    > for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do set
    > DateCode=%%a%%b%%c
    > (unwrap line)
    >
    > When I type echo %date% at a Command prompt then I get this: Tue
    > 11/05/2004
    > You may have to adjust the batch file to reflect your own date format.



    Hi Pegasus,
    Thanks for taking time to help me out.
    I saw that line before, were the For command is used to isolate date
    components, but I've still not been able to use it in a piped format.

    (I'm kinda unfamiliar with NT Scripts, Done a bit of UNIX, but usually
    work with client server VB/SQL type apps... so really appreciate your
    input)

    Sorry for getting you to spell it out for me but... should it be
    something like...

    for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do set
    DateCode=%%a%%b%%c
    dir >> %DateCode%.log

    (I can't get the variable recognised, as the file gets called
    "%DateCode%.log"

    Many thanks
    Danny

  4. Re: Redirecting Output to datestamped log.


    "DannyC" wrote in message
    news:4ee2d4a6.0405110139.507df23b@posting.google.c om...
    > "Pegasus \(MVP\)" wrote in message

    news:...
    > > "DannyC" wrote in message
    > > news:4ee2d4a6.0405100513.436d7ba0@posting.google.c om...
    > > > Hi Folks,
    > > >
    > > > Anyone know how to redirect output to a Datestamped file.... ie..
    > > >
    > > > dir >> {date/t}.log
    > > >
    > > > Looks like it should be simple enough, but I've been looking thru
    > > > posts, etc for a day now, and no soln yet.
    > > >
    > > > Thanks
    > > > Danny

    > >
    > > You were probably looking in the wrong areas - it's a VFAQ
    > > in batch file news groups. Here is a solution:
    > >
    > > @echo off
    > > for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do set
    > > DateCode=%%a%%b%%c
    > > (unwrap line)
    > >
    > > When I type echo %date% at a Command prompt then I get this: Tue
    > > 11/05/2004
    > > You may have to adjust the batch file to reflect your own date format.

    >
    >
    > Hi Pegasus,
    > Thanks for taking time to help me out.
    > I saw that line before, were the For command is used to isolate date
    > components, but I've still not been able to use it in a piped format.
    >
    > (I'm kinda unfamiliar with NT Scripts, Done a bit of UNIX, but usually
    > work with client server VB/SQL type apps... so really appreciate your
    > input)
    >
    > Sorry for getting you to spell it out for me but... should it be
    > something like...
    >
    > for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do set
    > DateCode=%%a%%b%%c
    > dir >> %DateCode%.log
    >
    > (I can't get the variable recognised, as the file gets called
    > "%DateCode%.log"
    >
    > Many thanks
    > Danny


    Follow these instructions verbatim:
    1. Paste the lines below into a file called "c:\Danny.bat".
    2. Make sure to unwrap the wrapped line.
    3. Type this at the Command Prompt: c:\Danny.bat
    4. Attach c:\Danny.bat in your reply.

    @echo off
    for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do
    set DateCode=%%a%%b%%c
    (unwrap line)
    echo rem Date=%date%>>%0
    echo rem DateCode=%DateCode%>>%0



  5. Re: Redirecting Output to datestamped log.

    danny@dublin.ie (DannyC) wrote in
    news:4ee2d4a6.0405110139.507df23b@posting.google.c om:

    > for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do set

    (wrapped line here)
    > DateCode=%%a%%b%%c
    > dir >> %DateCode%.log
    >
    > (I can't get the variable recognised, as the file gets called
    > "%DateCode%.log"


    When you do the set datecode=..., make sure to not have any spaces before
    the equal sign. Otherwise, you'll define the environment variable
    datecode. You mentioned doing some unix scripting; this is a quirk
    likely to catch a unix programmer because most unix shells don't behave
    this way. If this isn't the problem, run the script in a cmd session, then
    type SET which will list all defined environment variables and values.

  6. Re: Redirecting Output to datestamped log.

    "DannyC" wrote
    >
    > Anyone know how to redirect output to a Datestamped file.... ie..
    >
    > dir >> {date/t}.log
    >
    > Looks like it should be simple enough, but I've been looking thru
    > posts, etc for a day now, and no soln yet.
    >

    The FREE Advanced Command Library (ntlib.cmd) contains the GetLogDate
    command, which CONSISTENTLY returns yyyymmdd, regardless of differences in
    regional date formats. In your specific case:

    %.GetLogDate%
    DIR >>%#LogDate%.log

    *******

    Reference Pages:

    (http://TheSystemGuard.com/MtCmds/Get...GetLogDate.htm)
    (http://ntlib.com)

    -tsg

    /-----------------+---------------+----------------------\
    | COMPATIBILITY | CLARITY | SPEED |
    | Write code ONCE | Make it clear | THEN...Make it fast! |
    \-----------------+---------------+----------------------/
    400+ command-line resources using ONLY native NT commands!
    (http://TheSystemGuard.com/default.asp#MasterCommandList)



+ Reply to Thread