Help debugging simple .bat that worked on XP

Page 2 of 3 FirstFirst 123 LastLast

  1. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #11

    Ok. You need to change the following lines in the above code:

    Windows 7 compliant
    Code:
    set day=%date:~0,2%
    set mth=%DATE:~3,2%
    set yr=%DATE:~6,4%
    Windows XP equivalent
    Code:
    set day=%date:~4,2%
    set mth=%DATE:~7,2%
    set yr=%DATE:~10,4%
    The changes involve adding 4 to each of the pointers in order to jump over the unwanted part of the date in XP. There should be a way to incorporate both blocks of the above code into a batch file, and ensure that the correct section is executed dependant on the system the file is run on.

    The code in the following link should be able to help. I'll see if I can extract the necessary part and incorporate it into a new version of the batch file.

    http://stackoverflow.com/questions/1...-is-running-on
      My Computer


  2. Posts : 5,642
    Windows 10 Pro (x64)
       #12

    This is why I love Powershell, you can ask for a special date format instead of depending on the system to provide one you need. As well as a lot more power in Powershell.

    Code:
    $filedate = get-date -format "yyyy_MM_dd-HH*mm*ss"
    // 2011_06_03-08*42*42
      My Computer


  3. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #13

    Here you go.

    Code:
    @ECHO OFF
    ECHO TIME IS %TIME%
    ECHO DATE IS %DATE%
    set hour=%time:~0,2%
    set mn=%TIME:~3,2%
    set sc=%TIME:~6,2%
    set msec=%TIME:~9,2%
    if %hour% equ 0: set hour=00
    for /f "tokens=2 delims=[]" %%G in ('ver') Do (set _version=%%G)
    for /f "tokens=2,3,4 delims=. " %%G in ('echo %_version%') Do (set _major=%%G& set _minor=%%H& set _build=%%I)
    if "%_major%"=="5" goto sub5
    if "%_major%"=="6" goto sub6
    goto error
    :sub5
    set day=%date:~4,2%
    set mth=%DATE:~7,2%
    set yr=%DATE:~10,4%
    goto finish
    :sub6
    set day=%date:~0,2%
    set mth=%DATE:~3,2%
    set yr=%DATE:~6,4%
    goto finish
    :error
    echo "unsupported OS."
    echo.
    pause
    pause
    exit
    :finish
    set datefolder=%day%_%mth%_%yr%-%hour%*%mn%*%sc%
    echo datefolder is %datefolder%
    echo.
    pause
    pause
      My Computer


  4. Posts : 9
    Windows 7 Pro x64
    Thread Starter
       #14

    Sorry if I am adding confusion. This is all being done on Win 7 Pro x64
    SIW2 said:
    Fri 06/03/2011

    Looks like the issue.

    Recent o/s don't output the day.

    Also, is that 8AM ?

    8:05:59:18

    Different from 08:05:59:18
    8:05:59:18 is what is output. Yep, that 8am.


    Dwarf said:
    Ok. You need to change the following lines in the above code:

    Windows 7 compliant
    Code:
    set day=%date:~0,2%
    set mth=%DATE:~3,2%
    set yr=%DATE:~6,4%
    Windows XP equivalent
    Code:
    set day=%date:~4,2%
    set mth=%DATE:~7,2%
    set yr=%DATE:~10,4%
    The changes involve adding 4 to each of the pointers in order to jump over the unwanted part of the date in XP. There should be a way to incorporate both blocks of the above code into a batch file, and ensure that the correct section is executed dependant on the system the file is run on.

    The code in the following link should be able to help. I'll see if I can extract the necessary part and incorporate it into a new version of the batch file.

    how to tell what version of windows and/or cmd.exe a batch file is running on? - Stack Overflow
    I have the 7 compliant code in and it gives me a strange folder structure.
    I get folder 03 w/ subfolder under it of "_" and "_0_day"

    Maybe more info is needed. The folder is created correctly w/ orginal code, but the batch doesn't run correctly.

    Here' the whole(relevant) code:
    Code:
    set hour=%time:~0,2%
    if "%hour:~0,1%"==" "set hour=0%time:~1,1%
    set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%-%hour%.%time:~3,2%
    set DateFolder=%date:~10,4%_%date:~4,2%_%date:7,2%
    
    mkdir "\\path\%datefolder%\"
    
    7z a \\path\%folder%_machinename.zip \\path -xr!_backup -xr!Archive -ssw
    There's more, but that's the part that isn't working until 10am. Maybe it's a 7zip issue? The archive part was added for Win7 (I think I'm making a liar out of myself saying it worked on XP. I was sure it was a date/time context issue). 7zip tells me it can't find the .zip it's supposed to create, and continues on creating a .7z archive file instead of .zip. The "%datefolder%_machinename.zip file comes out with a "9.31_machinename.zip(thats 9:31am). The system cannot find the file specified. Again, until 10am. (using the original code)Then everything works great. I really appreciate the help!
      My Computer


  5. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #15

    Ok. Try this. It modifies the hour parameter so that it is always 2 characters long.
    Code:
    @ECHO OFF
    ECHO TIME IS %TIME%
    ECHO DATE IS %DATE%
    set hour=%time:~0,2%
    set mn=%TIME:~3,2%
    set sc=%TIME:~6,2%
    set msec=%TIME:~9,2%
    for /f "tokens=2 delims=[]" %%G in ('ver') Do (set _version=%%G)
    for /f "tokens=2,3,4 delims=. " %%G in ('echo %_version%') Do (set _major=%%G& set _minor=%%H& set _build=%%I)
    if "%_major%"=="5" goto sub5
    if "%_major%"=="6" goto sub6
    goto error
    :sub5
    set day=%date:~4,2%
    set mth=%DATE:~7,2%
    set yr=%DATE:~10,4%
    goto finish
    :sub6
    set day=%date:~0,2%
    set mth=%DATE:~3,2%
    set yr=%DATE:~6,4%
    goto finish
    :error
    echo "unsupported OS."
    echo.
    pause
    pause
    exit
    :finish
    if %hour% geq 10 goto finish1
    set hour=0%hour:~1,2%
    :finish1
    set datefolder=%day%_%mth%_%yr%-%hour%*%mn%*%sc%
    echo datefolder is %datefolder%
    echo.
    pause
    pause
    This means that if datefolder was 03_06_2011- 6*30*30 it will now be 03_06_2011-06*30*30. In other words, if the hours value is between 0 and 9, an additional leading 0 will be appended.
      My Computer


  6. Posts : 9
    Windows 7 Pro x64
    Thread Starter
       #16

    Thanks Dwarf. I'll try it tomorrow morning (before 10am :) Logicearth: Thanks. Yeah, I have hobbled together an auditing script with powershell, but I'm even less comfortable with it. Seems like that's were this stuff is going though.
      My Computer


  7. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #17

    You're welcome. I'll optimise the code and post back.
      My Computer


  8. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #18

    Optimised code (including error trapping).
    Code:
    @ECHO OFF
    set hour=%time:~0,2%
    if %hour% lss 10 set hour=0%hour:~1,2%
    for /f "tokens=2 delims=[]" %%G in ('ver') Do (set _version=%%G)
    for /f "tokens=2,3,4 delims=. " %%G in ('echo %_version%') Do (set _major=%%G& set _minor=%%H& set _build=%%I)
    if %_major% lss 5 goto error
    if %_major% gtr 6 goto error
    if "%_major%"=="5" set datefolder=%date:~4,2%_%date:~7,2%_%date:~10,4%-%hour%*%time:~3,2%*%time:~6,2%
    if "%_major%"=="6" set datefolder=%date:~0,2%_%date:~3,2%_%date:~6,4%-%hour%*%time:~3,2%*%time:~6,2%
    goto finish
    :error
    echo "Unsupported OS."
    echo.
    pause
    exit
    :finish
    mkdir "\\path\%datefolder%\"
    7z a \\path\%folder%_machinename.zip \\path -xr!_backup -xr!Archive -ssw
      My Computer


  9. Posts : 9
    Windows 7 Pro x64
    Thread Starter
       #19

    The results of the non-optimized code:
    datefolder is Sa_ 0_/04/-08*31*37

    EDIT: i just changed the date format in the Regonal setting, which fixed the output of the non-optimized code. I will try some more.......

    The optimized also seems to have the same issue. It creates nested directory's with strange names.
    I wonder if this is just not doable with windows 7 without powershell. If so, that's really a bummer cause the powershell scripts are much more complicated that what I had and what you've written. I will try your script after 10am to see if it works then.
    Last edited by jubxie; 04 Jun 2011 at 10:53. Reason: New results
      My Computer


  10. Posts : 9
    Windows 7 Pro x64
    Thread Starter
       #20

    That's it!!!!! I just had to get the date format correct so the output from the non-optimized code looked correct(does suck that it's hidden in regional settings, since I look previously and couldn't find it). And at 8:57am, I have a working backup script. And one that is much more robust than before. Can't thank you enough Dwarf. CHEERS!
      My Computer


 
Page 2 of 3 FirstFirst 123 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 13:02.
Find Us