Append behaves as (over)write

July 27, 2010 at 16:41:43
Specs: Windows 7 / 64 bit, Q9550 / 4 Gig
Hi there and congrats for your work here and your valuable help you provide!

I am a novice in batch scripting. I took a little from one answer, a little from another and I made a batch file for activating a game mod by adding commands in a txt file. This batch:

1. Checks if there is or not the uer.script.txt file. If not it creates one while writing the necessary mod commands.

2. If exists will do 2 checks. First will check if there is already the command by searching if the word Balkan is present (one is enough) and if yes will exit. If there is not will make a second check to see if it is blank or not by checking if there is present the word mod (every line in txt has at least one word 'mod').

3. If it is blank it will write the mod commands if not it will append them (Label 3). Here is the problem: It always overwrites the content of txt though I use append symbol >>.

Everything else works just fine. Here is the script:

@echo off
IF EXIST user.script.txt. (GOTO CHECKCONTENT) ELSE (GOTO LABEL5)

:CHECKCONTENT
findstr /i /c:"Balkan" user.script.txt >2
IF %errorlevel% EQU 0 (GOTO LABEL0) ELSE (GOTO LABEL1)

:LABEL0
GOTO END

:LABEL1
findstr /i /c:"mod" user.script.txt >2
IF %errorlevel% EQU 0 (GOTO LABEL3) ELSE (GOTO LABEL4)

:LABEL3
echo mod Balkan1_mod.pack; >> user.script.txt
echo mod Balkan2_mod.pack; >> user.script.txt

:LABEL4
echo mod Balkan1_mod.pack; > user.script.txt
echo mod Balkan2_mod.pack; >> user.script.txt

:LABEL5
echo mod Balkan1_mod.pack; > user.script.txt
echo mod Balkan2_mod.pack; >> user.script.txt

:END
Pause
Exit

Btw what is >2 in find string lines?

Thanks in advanced!


See More: Append behaves as (over)write

Report •

#1
July 28, 2010 at 03:15:45
I figured it out, I had to add a GOTO END command aster Label3. Just asking you was enough to solve my problem!!!

I would like an answer though about >2. Also can you point to me a guide/tutorial bout batch scripting that says more than, commands, syntax and a short description?


Report •

#2
July 28, 2010 at 03:42:11
>2 indicates standard output being redirected to a file simply named 2 in the current default directory.

Click the link for explanation of redirection.

http://www.robvanderwoude.com/redir...

Rob Vanderwoude's batch scripting tutorial might be worth investigating.

http://www.robvanderwoude.com/batch...

Good luck.


Report •

#3
July 28, 2010 at 04:34:27
Thanks a lot!

Report •
Related Solutions


Ask Question