views:

46

answers:

2

Hi,

I need a batch file that writes the count number to a txt file.

Next time the batch file is run, it should read the current count number from the txt file and add 1 to count and save this new value in the txt file. (nothing else is in the txt file) When count is >5 it should start from 1 again

Example: Count.bat runs 1 time:

count.txt has no count so Count.bat saves the value 1 in count.txt

Count.bat is run 2 time:

Count.bat reads 1 from count.txt and saves the new value 2 to count.txt

When count.bat is run for the 6 time it should start over by saving the value 1 in count.txt

I think this just be easy to do, but I'am not use to batch commands

So hopefully someone here could help me.

A: 

I know this isn't exactly what you asked for, but you may want to create separate files:

@echo off

if not exists count.1 goto l1
if not exists count.2 goto l2
if not exists count.3 goto l3
if not exists count.4 goto l4
if not exists count.5 goto l5

del count.*

rem -- fall trhough -- and create first count-file

:l1
echo . > count.1
goto end

:l2
echo . > count.2
goto end

:l3
echo . > count.3
goto end

:l4
echo . > count.4
goto end

:l5
echo . > count.5

rem -- fall through -- goto end

:end
thomask
A: 

Start with the file temp.txt with one line containing just a one (1) without parenthesis.

   for /f "eol=# tokens=* delims=," %%i in (temp.txt) do (
     set /A Count = %%i + 1
     If '%Count%' == '6' (set /A Count = 1)
   )
   echo %Count% > temp.txt
belisarius