Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Help debugging simple .bat that worked on XP

01 Jun 2011   #1
jubxie

Windows 7 Pro x64
 
 
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 System SpecsSystem Spec
.
01 Jun 2011   #2
Dwarf

Windows 8.1 Pro RTM x64
 
 

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 System SpecsSystem Spec
01 Jun 2011   #3
jubxie

Windows 7 Pro x64
 
 

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 System SpecsSystem Spec
.

01 Jun 2011   #4
SIW2

Microsoft Community Contributor Award Recipient

Vista x64 / 7 X64
 
 

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 System SpecsSystem Spec
01 Jun 2011   #5
jubxie

Windows 7 Pro x64
 
 

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 System SpecsSystem Spec
03 Jun 2011   #6
jubxie

Windows 7 Pro x64
 
 

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 System SpecsSystem Spec
03 Jun 2011   #7
Dwarf

Windows 8.1 Pro RTM x64
 
 

What do you see if you type date /t at a command prompt? Try on both XP and W7.
My System SpecsSystem Spec
03 Jun 2011   #8
SIW2

Microsoft Community Contributor Award Recipient

Vista x64 / 7 X64
 
 

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 System SpecsSystem Spec
03 Jun 2011   #9
jubxie

Windows 7 Pro x64
 
 

Date: Fri 06/03/2011

Time: 8:05:59:18

Thanks
My System SpecsSystem Spec
03 Jun 2011   #10
SIW2

Microsoft Community Contributor Award Recipient

Vista x64 / 7 X64
 
 

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 System SpecsSystem Spec
Reply

 Help debugging simple .bat that worked on XP




Thread Tools




Similar help and support threads
Thread Forum
Autocad worked Ok in XP why not in W7?
I've been using AutoCad 2004 in Wxp for years. But it wont work in W7. I've tried installing Oracle virtual box but it still wont run. I'm at the end of what I know can anyone help. Thanks
Software
Need help debugging CBS.log
Hi, I did sfc scan today and ran into some trouble. CMD output was: Beginning system scan. This process will take some time. Beginning verification phase of system scan. Verification 100% complete.
BSOD Help and Support
Windows Installer - Simple Fix that worked for me.
All the complicated fixes I've tried even those from Microsoft did not work. This one below work perfectly tor epair Windows Installer issues: HERE IS THE FIX THAT WORKED FOR ME : Start, then Run, then type regedit Go to HKEY_LOCAL_MACHINE\SYSTEM\CURRENT CONTROL ...
General Discussion
debugging help
Hi People, first post here, can anyone help me with this mini dump file i don't know how to fix my windows symbols so thought it would be easier to ask for help. been having a few BSOD lately. I'm running win 7 ultimate x64 retail
BSOD Help and Support
new to debugging
Hi please help me...im trying to view my DMP file with kernell debugger and a black dos screen flashes really quick but goes away..so i cant view anything ..Please help me cuz i want to find out what is wrong with my computer. Here are the bluescreens.
BSOD Help and Support
Games that Worked ok for me
Games that Worked ok for me: 1) NFS MW (1.3) 2) NFS Carbon (1.4) 3) Psi-Ops 4) Mass Effect
Gaming


Our Sites

Site Links

About Us

Find 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:00.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App