Question : DOS Script Fix

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


 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
@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

Answer : DOS Script Fix

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
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
@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
)
Random Solutions  
 
programming4us programming4us