Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

2003 cmd file help

  • 29-01-2006 04:29PM
    #1
    Registered Users, Registered Users 2 Posts: 902 ✭✭✭


    howdy all, ill make this quick, basically I'm trying to make a directory using the curent time and/or date for log files to be stored in.
    This is what I want to happen

    1. the script does it job, and then creates log files on several servers
    2. a logs folder is created from where the script is run
    3. at the end of the script it robocopies all the logs from the servers to the logs folder at one location from where it was run.

    The only problem I'm having is the syntax in creating the folder on Server 2003.

    On my XP workstation I used md h:\steve\%date% and it created h:\steve\29-Jan-06

    On W2003 it errored: The syntax of the command is incorrect.

    Eventually I used: md f:\sync\logs\"%date%" and this worked but it created the following directory structure: F:\sync\logs\Sun 01\29\2006 where I only want one sub-folder under logs...

    Any help would be greatly appreciated
    - Steve


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Two options.

    1) Store the date to a variable first, and parse through it changing all / to -
    2) Change the date formatting options on your servers Control Panel in the Regional and Language Options.


  • Registered Users, Registered Users 2 Posts: 902 ✭✭✭thesteve


    Thanks for the speedy reply!
    2) Change the date formatting options on your servers Control Panel in the Regional and Language Options.
    if only I had the rights...

    I'll read up on option number one, my batch file skills are basic, parsing is not something I've done before...

    Thanks again


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 96,136 Mod ✭✭✭✭Capt'n Midnight


    SET /? to see some options

    echo %DATE:~0,2%-%DATE~:3,2%-%DATE:~6,2%


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    Or, similarly:

    for /f "delims=/ tokens=1-3" %%a in ("%DATE%") do (
    set FILENAME=basename-%%c-%%b-%%a
    )
    echo %FILENAME%


Advertisement