considering with my scripts below, I want to count the number of characters inside the file. First, I want to count the lines and store it. Second given counted lines, I am now going to count for the number of characters. The process should be, the number of characters will be deducted with the number of lines counted. The problem is that when I use my scripts, the commands will no longer work, I don't if I am wrong with my scripts specially the use of SETLOCAL
cls
@echo off
set ctr=0
set str=
setlocal enabledelayedexpansion
FOR /f "tokens=*" %%G IN (file.txt) DO (call :count "%%G")
GOTO :eof
:count
set /a ctr+=1
goto :eof
setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%i in (file.txt) do (set str=!str! %%i)
call :len "%str%" a
setlocal enabledelayedexpansion
set /a a-=ctr
echo The string has %a% characters.
endlocal
goto :eof
:len <string> <length_variable>
setlocal enabledelayedexpansion
set l=0
set str=%~1
:len_loop
set x=!str:~%l%,1!
if not defined x (
endlocal
set "%~2=%l%"
goto :eof)
set /a l=%l%+1
goto :len_loop