Solved

DOS Script Fix

Posted on 2010-08-25
15
872 Views
Last Modified: 2012-06-27
I have a script and I am getting an error message. I am sure that I messed this script myself but for the life of me I can't see it. Another EE provided this support a while back and it worked fine for a long time, now just does not work

Error Message:
Invalid number.  Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
The system cannot find the batch label specified - DayNumber25
AB100_HOUR1_Seg1.mp3
AB100_HOUR1_Seg2.mp3
AB100_HOUR1_Seg3.mp3
AB100_HOUR1_Seg4.mp3
AB100_HOUR2_Seg1.mp3
AB100_HOUR2_Seg2.mp3
AB100_HOUR2_Seg3.mp3
AB100_HOUR2_Seg4.mp3
AB100_HOUR3_Seg1.mp3
AB100_HOUR3_Seg2.mp3
AB100_HOUR3_Seg3.mp3
AB100_HOUR3_Seg4.mp3


As you can see does not calculate the week anymore


 
@echo off

REM Set needed options
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION

REM Extract date components from current date
set /a MM=%DATE:~4,2%
set /a DD=%DATE:~7,2%
set /a YYYY=%DATE:~10,4%
set YY=%DATE:~12,4%

REM Get Weeknumber, then output filename
call :WeekNumber %MM% %DD% %YYYY%
for /L %%i in (1,1,3) do (
  for /L %%j in (1,1,4) do (
    set Filename=AB%YY%%Week%_HOUR%%i_Seg%%j.mp3
    echo !Filename!
  )
)
goto :EOF

:WeekNumber
REM Calculate an offset based on day of week January 1 fell on
set /a Offset=%3-1900
set /a Offset=((%Offset%+(%Offset%/4))%%7)+6
REM Find out what day of the year (from January 1) we are on
call :DayNumber %1 %2 %3
REM Add offset and then divide by 7 days per week
set /a Week=(%Day%+%Offset%)/7
goto :EOF

:DayNumber
REM Incrementally build up dy number from month and day
set /a Day=0
goto :DayNumber%1
:DayNumber12
set /a Day+=30
:DayNumber11
set /a Day+=31
:DayNumber10
set /a Day+=30
:DayNumber9
set /a Day+=31
:DayNumber8
set /a Day+=31
:DayNumber7
set /a Day+=30
:DayNumber6
set /a Day+=31
:DayNumber5
set /a Day+=30
:DayNumber4
set /a Day+=31
:DayNumber3
set /a Day+=28
REM Add an extra day on leap years
set /a Leap=%3 %% 4
if %Leap% == 0 set /a Day+=1
:DayNumber2
set /a Day+=31
:DayNumber1
set /a Day+=%2
goto :EOF

Open in new window

0
Comment
Question by:Barron1299
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 100 total points
Comment Utility
At a guess, it looks like the way your system is set to show DOS's dates has changed.

Today is day 25 and month 8.

The code has labels which reflect adding the number of days in the month to a value.

The labels are ... DayNumberX ... where x is the MONTH number.

As you are getting DayNumber25, the day and the month are the wrong way around.

So, take a look at the system settings for the formats of the date ...

Control Panel
Regional and Language Options
Customize button.
Date tab
Short date format needs to be changed so that the dd and the mm are the other way around, but the yyyy doesn't move.

So, if it currently says ...

dd/mm/yyyy

change it to ...

mm/dd/yyyy


I have code which does away with this issue.

I'll come back when I've found it...

0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Try changing the code ...


REM Extract date components from current date
set /a MM=%DATE:~4,2%
set /a DD=%DATE:~7,2%
set /a YYYY=%DATE:~10,4%
set YY=%DATE:~12,4%

to the snippet below.

Essentially, it uses the DATE command to determine the order of the DD, MM and YYYY components of the current date.

No matter what the order (YYYY/MM/DD, DD/YYYY/MM, DD/MM/YYYY, MM/DD/YYYY, etc.)

REM Extract date components from current date

REM set /a MM=%DATE:~4,2%

REM set /a DD=%DATE:~7,2%

REM set /a YYYY=%DATE:~10,4%

REM set YY=%DATE:~12,4%



FOR /F "tokens=1-3 delims=.-/: " %%A IN ("%DATE%") DO (

	FOR /F "tokens=2-4 skip=1 delims=(.-/)" %%D IN ('VER^|DATE') DO (

		SET %%D=%%A

		SET %%E=%%B

		SET %%F=%%C

	)

)

SET YYYY=%YY%

Open in new window

0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
This is what I get when I run it:


C:\test>weeknum

C:\test>rem @echo off

C:\test>REM Set needed options

C:\test>setlocal ENABLEEXTENSIONS

C:\test>setlocal ENABLEDELAYEDEXPANSION

C:\test>REM Extract date components from current date

C:\test>set /a MM=08
Invalid number.  Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).

C:\test>pause
Press any key to continue . . .

I don't see a problem with MM=08 but the code sure does.  
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Leading 0 means OCTAL.

8 is not a valid octal number.

Octal uses values 0-7.
Decimal uses values 0-9
Binary uses 0-1

The code is flawed in this regard.
0
 
LVL 1

Author Comment

by:Barron1299
Comment Utility
Okay changed the date format to MM/dd/yyyy and replaced the code and now this is what I get displayed:

The system cannot find the batch label specified - DayNumber08
AB20101_HOUR1_Seg1.mp3
AB20101_HOUR1_Seg2.mp3
AB20101_HOUR1_Seg3.mp3
AB20101_HOUR1_Seg4.mp3
AB20101_HOUR2_Seg1.mp3
AB20101_HOUR2_Seg2.mp3
AB20101_HOUR2_Seg3.mp3
AB20101_HOUR2_Seg4.mp3
AB20101_HOUR3_Seg1.mp3
AB20101_HOUR3_Seg2.mp3
AB20101_HOUR3_Seg3.mp3
AB20101_HOUR3_Seg4.mp3

Here is what is should look like for this week
AB80S1035_HOUR1_SEG1.mp
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Change the labels so, that DayNumber1 to DayNumber9 become DayNumber01 to DayNumber09

0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
:DayNumber7
set /a Day+=30
:DayNumber6
set /a Day+=31
:DayNumber5
set /a Day+=30

becomes ...

:DayNumber07
set /a Day+=30
:DayNumber06
set /a Day+=31
:DayNumber05
set /a Day+=30

etc.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
==> Barron1299

Can you do the following command at a command prompt and tell me what you get:

ECHO %DATE%

~bp
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 400 total points
Comment Utility
Okay, give this a try, it uses a more robust routine to get the current date components than we used before.  I also fixed the bug on the week number so that it will be zero filled when less than 10.  Let me know how this goes.

~bp
@echo off
 
REM Set needed options
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
 
REM Extract date components from current date
call :GetDate "MM" "DD" "YYYY"
set YY=%YYYY:-2%
 
REM Get Weeknumber, then output filename
call :WeekNumber %MM% %DD% %YYYY%
for /L %%i in (1,1,3) do (
  for /L %%j in (1,1,4) do (
    set Filename=AB%YY%%Week%_HOUR%%i_Seg%%j.mp3
    echo !Filename!
  )
)
exit /b
 
:WeekNumber
  REM Calculate an offset based on day of week January 1 fell on
  set /a Offset=%3-1900
  set /a Offset=((%Offset%+(%Offset%/4))%%7)+6
  REM Find out what day of the year (from January 1) we are on
  call :DayNumber %1 %2 %3
  REM Add offset and then divide by 7 days per week
  set /a Week=(%Day%+%Offset%)/7
  if %Week% LSS 10 set Week=0%Week%
  exit /b
 
:DayNumber
  REM Incrementally build up dy number from month and day
  set /a Day=0
  goto :DayNumber%1
:DayNumber12
  set /a Day+=30
:DayNumber11
  set /a Day+=31
:DayNumber10
  set /a Day+=30
:DayNumber9
  set /a Day+=31
:DayNumber8
  set /a Day+=31
:DayNumber7
  set /a Day+=30
:DayNumber6
  set /a Day+=31
:DayNumber5
  set /a Day+=30
:DayNumber4
  set /a Day+=31
:DayNumber3
  set /a Day+=28
  REM Add an extra day on leap years
  set /a Leap=%3 %% 4
  if %Leap% == 0 set /a Day+=1
:DayNumber2
  set /a Day+=31
:DayNumber1
  set /a Day+=%2
  exit /b
 
:GetDate [month-variable] [day-variable] [year-variable]
  REM Get date format settings from registry
  rem For REG.EXE 3.0 (Windows XP) and later versions
  for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International" /v iDate 2^>NUL') do set "iDate=%%A"
  for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International" /v sDate 2^>NUL') do set "sDate=%%A"
  rem For earlier REG.EXE versions
  rem for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International\iDate" 2^>NUL') do set "iDate=%%A"
  rem for /F "tokens=3" %%A in ('reg query "HKCU\Control Panel\International\sDate" 2^>NUL') do set "sDate=%%A"

  REM Get the current system date (ignore day name if present)
  for %%A in (%Date%) do set "Today=%%A"

  REM Parse current date based on delimiter from registry, and assign to desired user variable
  for /F "tokens=1-3 delims=%sDate%" %%A in ("%Today%") do (
    if "%iDate%"=="0" set /a "%~2=1%%B-100" & set /a "%~1=1%%A-100" & set "%~3=%%C"
    if "%iDate%"=="1" set /a "%~2=1%%A-100" & set /a "%~1=1%%B-100" & set "%~3=%%C"
    if "%iDate%"=="2" set /a "%~2=1%%C-100" & set /a "%~1=1%%B-100" & set "%~3=%%A"
  )
  exit /b
)

Open in new window

0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Sorry, one small typo, please chane:

set YY=%YYYY:-2%


to:

set YY=%YYYY:~-2%


~bp
0
 
LVL 1

Author Comment

by:Barron1299
Comment Utility
echo %date% = 08/25/2010


Looks like it is working again, thanks Bill. Now someone mentioned there would be a way to eliminate having to change the regional settings date display, is that possible. If so let me know and I will create a new questions so to give points?

For now, while Bill did actual get the script right, RQuadling did help with changing the date display, so I have to be fair on the points distribution.
0
 
LVL 1

Author Closing Comment

by:Barron1299
Comment Utility
Great help folks, thank you very much!
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Getting the date parts in DOS has MANY solutions.

Glad to have helped.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
==> Looks like it is working again, thanks Bill. Now someone mentioned there would be a way to eliminate
==> having to change the regional settings date display, is that possible. If so let me know and I will create
==> a new questions so to give points?

My last post included the :GetDate routine approach, which adapts to different regional date formats.  You shouldn't have to adjust the script again.

~bp
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
I use the following code to produce a set of environment variables containing the current date and time.

I can also pass it a date (say a files datetime) and get that parsed too.

The variables end up as

YY, MM, DD, HH, II and SS.

I just run the batch file and the values are ...

dd=26
hh=13
ii=01
mm=08
ss=56
yy=2010

Changing the regional settings won't alter the behaviour.
@ECHO OFF
IF "%~1"=="" (
	SET MakeDate_Request=%DATE% %TIME%
) ELSE (
	SET MakeDate_Request=%~1
)
FOR /F "tokens=1-6 delims=.-/: " %%A IN ("%MakeDate_Request%") DO (
	FOR /F "tokens=2-4 skip=1 delims=(.-/)" %%G IN ('VER^|DATE') DO (
		SET %%G=%%A
		SET %%H=%%B
		SET %%I=%%C
		SET hh=%%D
		SET ii=%%E
		SET ss=%%F
	)
)
IF "%ss%"=="" SET ss=00
SET MakeDate_Request=

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now