BATCH file help

Discussion in 'Web Design & Coding' started by dillinja, Mar 24, 2006.

  1. dillinja

    dillinja OSNN Junior Addict

    This BATCH file works (I have only copied the upper part of the BATCH file), but only if there are 2 digits in the hour. If there is only one digit in the hour (eg 07:12) it fails because it puts a gap where the o' should be. How can I get the script to enter a two digit hour by default (eg '07') or alternatively handle the gap.

    @echo off
    for /F "usebackq tokens=1 delims=/ " %%i in ('%DATE%') do set day=%%i
    for /F "usebackq tokens=2 delims=/ " %%i in ('%DATE%') do set month=%%i
    for /F "usebackq tokens=3 delims=/ " %%i in ('%DATE%') do set year=%%i
    for /F "usebackq tokens=1 delims=:" %%i in ('%TIME%') do set hour=%%i
    for /F "usebackq tokens=2 delims=:" %%i in ('%TIME%') do set minute=%%i
    set Date_Dir=%year%%month%%day%-%hour%%minute%

    echo Exporting to %Date_Dir% direcory
    if not exist %Date_Dir% mkdir %Date_Dir%