• .bats

    From Paul Hayton@3:770/100 to Spiro Dotgeek on Sat Oct 18 12:34:55 2014
    I'm having a moment, can you help? :-)

    I just want to set up a .bat file in my windows box to take a log file,
    rename it with a date/timestamp and then move /copy it off to another dir.

    It's the setting of date/time vars and/or calling them correctly when I try to envoke a rename command on the target file that eludes me.


    I found the following but it's not setting the date/time var up correctly and does not work

    c:
    cd\hub\logs

    for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
    set "YY=%dt:~2,2%"
    set "YYYY=%dt:~0,4%"
    set "MM=%dt:~4,2%"
    set "DD=%dt:~6,2%"
    set "HH=%dt:~8,2%"
    set "Min=%dt:~10,2%"
    set "Sec=%dt:~12,2%"

    set datestamp=%YYYY%%MM%%DD%
    set timestamp=%HH%%Min%%Sec%
    set fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%

    ren "c:\hub\logs\fecho.txt" "%fullstamp%.txt"
    goto done


    `I'm not expendable, I'm not stupid, and I'm not going' - Kerr Avon, Blake's 7

    --- Mystic BBS v1.10 A52 (Windows)
    * Origin: Agency BBS | telnet://agency.bbs.geek.nz (3:770/100)
  • From Spiro Dotgeek@3:772/300 to Paul Hayton on Sat Oct 18 20:03:56 2014
    I'm having a moment, can you help? :-)
    I just want to set up a .bat file in my windows box to take a log file, rename it with a date/timestamp and then move /copy it off to another
    dir.

    I don't actually know anything about batch scripting on windows. I'm a unix
    guy through and through, and that whole script could be replaced with a one-liner in linux:

    mv $sourcefile $(date +"%Y-%m-%d_%H-%M-%S").txt

    :)

    I did start looking into that script, but I think windows uses variables differently on the command line and in scripts, and one uses %% and one uses
    % and I can't remember which is which.

    for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"

    If I run the wmic command from the CLI, it doesn't work if I include the ^ symbol.

    And I can't see why the delims are set to nothing (ie; "delims=" when there
    are no characters that act as delimiters in the output of the wmic command.
    So that just seems pointless.

    But I get different errors depending on which parts of the code I try to
    "fix."

    BAT files really are just batch files. That is, a batch of CLI commands. It's not a scripting language or script interpreter, and you're really hamstrung
    by it. My understanding is that windows powershell fixes this hole, but I've never used it myself.

    Another option open to you would be to install Cygwin, which gives you unix-like commands and scripting power from Windows.

    Although, if this is your only scripting requirement that might be overkill.
    :)

    Just found this on powershell renaming:

    http://stackoverflow.com/questions/14945253/powershell-file-rename-date-time

    and wow.. this piece of code:

    Get-ChildItem "$dlpath\*.pgp" | ForEach-Object {
    Move-Item $_.FullName "$BackupFolder$($_.BaseName -replace " ", "_" -replace '\.([^\.]+)$')-$(Get-Date -Format "MMddyyyy-HHmmss").pgp"
    }

    shows me Windows is waaaaaay too complex for me.

    :) Sorry, outta my league.

    --- Mystic BBS v1.10 A52 (Linux)
    * Origin: The Shadow Dominion BBS (3:772/300)
  • From Paul Hayton@3:770/100 to Spiro Dotgeek on Sat Oct 18 20:16:57 2014
    On 10/18/14, Spiro Dotgeek pondered and said...

    :) Sorry, outta my league.

    Heh... yeah me too I'm going to seek wider help in another echo. What I supplied I sourced from the net and it's not working as expected but then I think that's because there are differing versions of DOS :-(

    Fun times for a Saturday night!


    `I'm not expendable, I'm not stupid, and I'm not going' - Kerr Avon, Blake's 7

    --- Mystic BBS v1.10 A52 (Windows)
    * Origin: Agency BBS | telnet://agency.bbs.geek.nz (3:770/100)
  • From Paul Hayton@3:770/100 to Spiro Dotgeek on Sat Oct 18 20:36:58 2014
    On 10/18/14, Spiro Dotgeek pondered and said...

    I don't actually know anything about batch scripting on windows. I'm a unix guy through and through, and that whole script could be replaced
    with a one-liner in linux:


    Success it's %date:~-4,4%-%date:~-7,2%-%date:~-10,2%-filename.txt

    From the web

    The :~ substring command works like this:

    :~[START POS],[LENGTH]

    If [START_POS] is positive or zero the substring will start from the left. If the number [START_POS] is negative it will start from the right. And [LENGTH] is the number of characters in the opposite direction of the starting point.


    `I'm not expendable, I'm not stupid, and I'm not going' - Kerr Avon, Blake's 7

    --- Mystic BBS v1.10 A52 (Windows)
    * Origin: Agency BBS | telnet://agency.bbs.geek.nz (3:770/100)
  • From Spiro Dotgeek@3:772/300 to Paul Hayton on Sun Oct 19 08:54:00 2014
    Heh... yeah me too I'm going to seek wider help in another echo. What I supplied I sourced from the net and it's not working as expected but
    then I think that's because there are differing versions of DOS :-(

    Not terribly surprising. So much for compatibility. :(

    Fun times for a Saturday night!

    What are you doing at home? You should have been HAMming it up at Shag
    Valley! ;)

    --- Mystic BBS v1.10 A52 (Linux)
    * Origin: The Shadow Dominion BBS (3:772/300)
  • From Spiro Dotgeek@3:772/300 to Paul Hayton on Sun Oct 19 08:56:01 2014
    Success it's %date:~-4,4%-%date:~-7,2%-%date:~-10,2%-filename.txt

    Cool! That's a lot less convoluted. haha

    The :~ substring command works like this:
    :~[START POS],[LENGTH]

    That's a good one to know.

    --- Mystic BBS v1.10 A52 (Linux)
    * Origin: The Shadow Dominion BBS (3:772/300)
  • From Paul Hayton@3:770/100 to Spiro Dotgeek on Sun Oct 19 12:17:02 2014
    On 10/19/14, Spiro Dotgeek pondered and said...

    What are you doing at home? You should have been HAMming it up at Shag Valley! ;)

    Heh, yep.... I have kids at learn to sail classes on Sunday morning so based
    at home this weekend. Still I can give it a push on Fido. I'm getting a lot
    of emails coming into the webmaster account on zl4aa.org from a bunch of HAM operators making contact with the station - really cool.


    `I'm not expendable, I'm not stupid, and I'm not going' - Kerr Avon, Blake's 7

    --- Mystic BBS v1.10 A52 (Windows)
    * Origin: Agency BBS | telnet://agency.bbs.geek.nz (3:770/100)
  • From Paul Hayton@3:770/100 to Spiro Dotgeek on Sun Oct 19 12:18:03 2014
    On 10/19/14, Spiro Dotgeek pondered and said...

    Cool! That's a lot less convoluted. haha

    The :~ substring command works like this:
    :~[START POS],[LENGTH]

    That's a good one to know.

    Always a good feeling when you suss a problem. That and getting your .bat to
    do what it should!


    `I'm not expendable, I'm not stupid, and I'm not going' - Kerr Avon, Blake's 7

    --- Mystic BBS v1.10 A52 (Windows)
    * Origin: Agency BBS | telnet://agency.bbs.geek.nz (3:770/100)
  • From Spiro Dotgeek@3:772/300 to Paul Hayton on Sun Oct 19 13:19:04 2014
    Heh, yep.... I have kids at learn to sail classes on Sunday morning so based at home this weekend. Still I can give it a push on Fido. I'm getting a lot of emails coming into the webmaster account on zl4aa.org from a bunch of HAM operators making contact with the station - really cool.

    That's great. And seeing that there are big organised events will motivate me to push for getting my license, or at least studying hard for it. :)

    --- Mystic BBS v1.10 A52 (Linux)
    * Origin: The Shadow Dominion BBS (3:772/300)
  • From Spiro Dotgeek@3:772/300 to Paul Hayton on Sun Oct 19 13:20:05 2014
    Always a good feeling when you suss a problem. That and getting your
    .bat to do what it should!

    haha, yeah, and no matter how often I tell myself "I must test my scripts in
    a non-destructive environment," it's yet to sink in. ;)

    --- Mystic BBS v1.10 A52 (Linux)
    * Origin: The Shadow Dominion BBS (3:772/300)