Use este código. A entrada é foo.txt
e a saída é foobar.txt
. Eu não entendo como a recursão funciona na variável %% b, mas no shell de comando regular do Windows 7 Pro.
@echo off
setlocal enabledelayedexpansion
goto afterfunctions
REM http://stackoverflow.com/questions/5837418/how-do-you-get-the-string-length-in-a-batch-file
:trimstring <therestVar> <inputVar>
(
setlocal EnableDelayedExpansion
for /f "tokens=1,* delims=:" %%a in ("!%~2!") do (
echo %%a
REM echo %%b
REM %%b is the rest of it. Now we need to call this function with just that string.
call :trimstring result %%b
)
)
(
endlocal
exit /b
)
:afterfunctions
for /f "delims=" %%x in (foo.txt) do set mystring=%%x
set thisstring=%mystring%
call :trimstring result mystring > foobar.txt
:eof