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

03 Jun 2011   #11
Dwarf

Windows 8.1 Pro RTM x64
 
 

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 System SpecsSystem Spec
.
03 Jun 2011   #12
logicearth

Windows 10 Pro (x64)
 
 

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

Windows 8.1 Pro RTM x64
 
 

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

03 Jun 2011   #14
jubxie

Windows 7 Pro x64
 
 

Sorry if I am adding confusion. This is all being done on Win 7 Pro x64
Quote   Quote: Originally Posted by SIW2 View Post
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.


Quote   Quote: Originally Posted by Dwarf View Post
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 System SpecsSystem Spec
03 Jun 2011   #15
Dwarf

Windows 8.1 Pro RTM x64
 
 

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

Windows 7 Pro x64
 
 

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

Windows 8.1 Pro RTM x64
 
 

You're welcome. I'll optimise the code and post back.
My System SpecsSystem Spec
03 Jun 2011   #18
Dwarf

Windows 8.1 Pro RTM x64
 
 

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 System SpecsSystem Spec
04 Jun 2011   #19
jubxie

Windows 7 Pro x64
 
 

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.
My System SpecsSystem Spec
04 Jun 2011   #20
jubxie

Windows 7 Pro x64
 
 

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