Solved

DOS Script Fix

Posted on 2010-08-25
15
878 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
ID: 33526825
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
ID: 33526847
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
ID: 33526926
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
ID: 33526939
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
ID: 33526984
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
ID: 33526996
Change the labels so, that DayNumber1 to DayNumber9 become DayNumber01 to DayNumber09

0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33526999
: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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 52

Expert Comment

by:Bill Prew
ID: 33527227
==> Barron1299

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

ECHO %DATE%

~bp
0
 
LVL 52

Accepted Solution

by:
Bill Prew earned 400 total points
ID: 33527319
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 52

Expert Comment

by:Bill Prew
ID: 33527325
Sorry, one small typo, please chane:

set YY=%YYYY:-2%


to:

set YY=%YYYY:~-2%


~bp
0
 
LVL 1

Author Comment

by:Barron1299
ID: 33527821
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
ID: 33527827
Great help folks, thank you very much!
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33529187
Getting the date parts in DOS has MANY solutions.

Glad to have helped.
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33530405
==> 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
ID: 33530467
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

26 Experts available now in Live!

Get 1:1 Help Now