Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
this question should be easy, but i am not a programmer. so you may want to talk at a novice level.
my problem is this, i need to write a batch file or script that will keep a running count (a batch file would be preferable). when i launch the file it needs to have 2 counters that it references (i assume). i am running the program m-f, every mon-thurs it should run one script (call it code 1 - i already have this - it is a batch file command). for 3 fridays it should run another script (not code 1, but code 2 - i already have this - it is a batch file command). on every 4th friday it should run another script (only code 3 - i have this - it is a batch file command). S/one else helped me a lot to write this code, but it gives me a "The syntax of the command is incorrect" error. Can s/one please help me fix the code?:=====8<-------[ TapecopyToTape.bat ]---------
@ECHO OFF
TITLE Tapecopy - Copying DISK to TAPE
SETLOCAL ENABLEDELAYEDEXPANSIONcd\
cd\Program Files\CA\Brightstor ARCserve Backup\SET CountFile=CountFile.txt
SET code1=TAPECOPY -qPASTTIME 1 -dGROUP1 -mGTCTAPE_DLY -g
SET code2=TAPECOPY -qPASTTIME 1 -dGROUP1 -mGTCTAPE_WLY -g
SET code3=TAPECOPY -qPASTTIME 1 -dGROUP1 -mGTCTAPE_MLY -gIF NOT EXIST "%CountFile%" (ECHO 0>"%CountFile%" & ECHO 0>>"%CountFile%"
SET TempCount=1
FOR /f "tokens=*" %%C in (%CountFile%) do CALL :COUNT_0 "%%C"GOTO :NEXT_0
:COUNT_0
SET Count!TempCount!=%~1
SET /a TempCount+=1
EXIT /B:NEXT_0
SET /a Count1+=1
IF %Count1% LSS 5 (
%code1%
GOTO :EOF
) ELSE (
IF %Count1% GEQ 5 ( SET /a Count2+=1 )
)IF %Count2% LSS 4 (
%code2%
SET Count1=0
GOTO :EOF
) ELSE (
IF %Count2% GEQ 4 (
%code3%
SET Count1=0 & SET Count2=0
GOTO :EOF
)
):EOF
ECHO %Count1%>%CountFile%
ECHO %Count2%>>%CountFile%:=====8<-------[ TapecopyToTape.bat ]---------

Hi
IF NOT EXIST "%CountFile%" (ECHO 0>"%CountFile%" & ECHO 0>>"%CountFile%"This line should have an end bracket ")"
I take it this line puts 2 blank lines in the CountFile.txt and then this command would read these two blank lines. Is this what you require.
FOR /f "tokens=*" %%C in (%CountFile%) do CALL :COUNT_0 "%%C"
and how does this batch file know what weekday it is.Is this what you need help with.
if so what does the command "echo %date% produce on your machine.

This might give you some ideas.
Type in the code below to create Weekday.txt
for <enter> just press the enter key to create
a blank line.
This when run returns the Errorlevels of
0 for Sunday, 1 for Monday and so on.
the enter "debug < Weekday.txt" this will create
Weekday.com, Weekday.txt can then be deleted if
you want.--
n Weekday.com
a
mov ah,2a
int 21
mov ah,4c
int 21
<Enter>
r cx
8
w
q
----------------------
This will give you some idea of what you need
delete the rem's and echo's that display the commands
ie echo %Code%mth -g ect.
----------------
@echo offrem Create NoFridays.txt with the WeekNo you want to start with
rem change the echo 0 to echo 1 2 3
if not exist NoFridays.txt echo 0 >NoFridays.txtrem Set environment variable
set Code=tapecopy -qpasttime 1 -dgroup1 -gtctape_rem call Weekday.com to day of week to set Errorlevel
rem 0 Sunday, 1 Monday ect.
weekday.comrem Check Errorlevel
rem Not Sat or Sun
if errorlevel 6 goto NoWay
if errorlevel 0 ;if not errorlevel 1 goto NoWayrem Monday-Thursday
if errorlevel 1 ;if not errorlevel 5 goto Mon-Thurem Here if it's a Friday
rem set FriCount to number in NoFridays.txt
set /p FriCount=<NoFridays.txt
rem set FriCount to (FriCount+1) modulus 4
set /a FriCount=(%FriCount%+1)%%4
rem write number back to NoFridays.txt
echo %FriCount% > NoFridays.txtecho Friday Week %FriCount%
rem if not 0 it's weekly
rem else its Friday, time for the monthly
rem delete the echo's to execute your program
if %FriCount% neq 0 (
echo %Code%wly -g
) else (
echo %code%mly -g
)
exit /b:NoWay
echo Mon-Thu Only
exit /b:Mon-Thu
echo Mon-Thu
echo %Code%dly -g
------

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |