In a batch file I want to count lines in files in a few directories and use the line count in an environment variable later in that batch. For example, consider I have the following files:
Directory1\update.log (1 line)
Directory2\update.log (2 lines)
Directory3\update.log (3 lines)
This is the batch file I'm using:
for /d %%d in (*.*) do (
echo Processing %%d
cd %%d
for /f %%c in ('find /v /c "" ^< update.log') do set count=%%c
echo Count is %count%
cd ..
)
Now I open a new command window and call that batch. The results of the first call are:
Processing Directory1
Count is
Processing Directory2
Count is
Processing Directory3
Count is
And any subsequent call in the same command window results in
Processing Directory1
Count is 3
Processing Directory2
Count is 3
Processing Directory3
Count is 3
What am I doing wrong here?