Help debugging simple .bat that worked on XP

Page 1 of 3 123 LastLast

  1. Posts : 9
    Windows 7 Pro x64
       #1

    Help debugging simple .bat that worked on XP


    Hello,

    I have a backup .bat that I have hobbled together from forums such as this. The original was made a few years ago. It worked flawlessly, until I brought it to windows 7. Very funny, now, it only works between 10am and midnight. This has been hell to figure out because sometimes it works and sometimes it doesn't. I know it has something to do with the context of the "set hour" or "if "%hour.." part, but I can't figure it out. Should be an easy fix for someone familiar with .bat programming. Here is the relevant part:

    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%
    Let me know if you need more info. I have to hand type the code, since the original is on a non-networked machine. Thanks!
      My Computer


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

    Hi jubxie and welcome to W7 Forums

    Change the second line to the following: if "%hour:~0,1%"==" "set hour=0%time:~1,1%
      My Computer


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

    Thank you for the help. My mistake. That is what I have in the .bat. I had a typo in my post. I never had any trouble with this before on XP pro SP3. If it helps, the meat of the .bat is a command to place the contents of a folder in a .zip file using 7zip and robocopying the data to a server. Those commands all work correctly on the command line, stand alone. Any other ideas?
      My Computer


  4. Posts : 16,119
    7 X64
       #4

    Looks awful complicated, would this be easier?

    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
    echo.
    set day=%date:~0,2%
    set mth=%DATE:~3,2%
    set yr=%DATE:~6,4%
    echo.
    set datefolder=%day%_%mth%_%yr%-%hour%*%mn%*%sc%
    echo.
    echo datefolder is %datefolder%
    echo.
    pause
    outputs this:

    TIME IS 21:02:58.78
    DATE IS 01/06/2011

    datefolder is 01_06_2011-21*02*58

    Press any key to continue . . .
      My Computers


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

    Thanks. I will try that and let you know. I'll have to wait til Friday morning before 10am, but I will post results.
      My Computer


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

    Interesting. Running that exact (copy and paste) gave me very different results. Did you run on XP? My results:
    datefolder is Fr_ 0_/03/- 7*50*52.

    There must be something different about how 7 interprets this code. Any other ideas I could test before 10am PT, at which point the original code will start to work?
      My Computer


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

    What do you see if you type date /t at a command prompt? Try on both XP and W7.
      My Computer


  8. Posts : 16,119
    7 X64
       #8

    No, I don't have XP.

    Might be different on an ancient o/s.

    Try just checking what it gives you for %time% and %date% - try directly in cmd window, like this:

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Windows\System32>ECHO TIME IS %TIME%
    TIME IS 16:01:11.39

    C:\Windows\System32>ECHO DATE IS %DATE%
    DATE IS 03/06/2011

    C:\Windows\System32>

    date /t should also work as Dwarf says.
      My Computers


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

    Date: Fri 06/03/2011

    Time: 8:05:59:18

    Thanks
    Last edited by jubxie; 03 Jun 2011 at 10:06. Reason: 2 quick replys
      My Computer


  10. Posts : 16,119
    7 X64
       #10

    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
      My Computers


 
Page 1 of 3 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 00:53.
Find Us