1.

Solve : Totalling in Bat Files?

Answer»

In my bat file, I am copying print files to a directory. I need to count each time I log an entry of a file that was COPIED to that directory. Is there a way in DOS, via the BAT file that I can take a running total of the files and update the log file with this total? I know that you can perform a CALL to a subroutine, but is there a DOS total function that I can make a CALL to?Without knowing your OS, you may be able to use the set /a batch command. This will allow you to do simple integer arithmetic.

If you are using a wildcard in your copy there would be no way to intercept and count each file.

You don't need a subroutine, you can use inline code. You can use redirection to push the total into your log file.

There is no built in DOS total function. Get back to us if you need more info, but mention your OS and POST your batch file.

Hope this helps. Won't using a simple LOOP will server your purpose.

Just increment your counter in the loop.We are using Windows 2003 server. You certainly brought something to light that I totally forgot and that is that we are copying globally. We could actually be copying more than one file at a time. Anyway, if you can, will you please provide a code example on how you would use the set /a command and the code to add to the counter for a batch file. I would appreciate it since I am not a DOS programmer.

Also, Vibhor mentioned using a simple loop, just increment the count in the loop. Can you provide an example?
Thank you so MUCH. Ernest.This simple loop, which I posted earlier to another user, will provide a loop and count arguments passed to the batch file

Code: [Select]
@echo off
set count=0
:start
if .%1==. goto next
set /a count=%count%+1
shift
goto start
:next
echo %count% arg(s) were passed


As mentioned global copies are not practical. You would only count the number of copy statements executed not the number of files. As with any loop, you must provide a way to exit.

In a Win2003 environment, a script would be more practical, easier to read, and you would have more control over what does and does not get counted.

Hope this gives you some ideas you can use to customize to your environment. Sidewinder,
Thank you so much for your help. I think you are correct. I will do this in VB and call it. However, since we do use DOS in our production cycle, I can probably use your example further down the road. Again, thanks for your help. We do appreciate it. Ernest.



Discussion

No Comment Found