1.

Solve : How to count...?

Answer»

How do you count the files in a map with of course MS-DOSI'm guessing that map REFERS to a directory.

This will do the basic job:

Code: [Select]ECHO off
set count=0
for /f %%v in ('dir *.txt /b') do (
call set /a count=%%count%%+1
)
echo Count: %count%

Will count all txt files in the directory where this batch code is located.

 Yes, Larssie, this is a map



Sidewinder uses that old DOS CALL thing but you can get modern like this

echo off
setlocal enabledelayedexpansion
set /a count=0
for /f %%v in ('dir /b /a-d') do (
    set /a count=!count!+1
    )
echo Count: %count% Quote

Sidewinder uses that old DOS CALL thing but you can get modern like this

Actually it has more to do with variable scope. Variables declared after a setlocal remain in scope until an endlocal statement or the end of the batch file, whichever comes FIRST. By not USING a setlocal statement, variables remain in scope until the shell window is closed.



Discussion

No Comment Found