He made a small error. He was using %f% where he needed to use %in%. ...or simply %2. Also, I changed foo.bat to %0.
@echo off
IF "%1" == "process" GOTO processFile
GOTO convertAll
:convertALL
FOR %%f IN (c:\temp\*.txt) DO CALL %0 process "%%f"
GOTO end
:processFile
perl -p -i.bak -e "s/change this/to this/g" %2
del %2.bak
GOTO end
:end
If you really wanted to name the parameter, try the following. It cleans up the environment as a bonus (by spawning another shell where CALL was formerly used).
@echo off
IF "%1" == "process" GOTO processFile
GOTO convertAll
:convertALL
FOR %%f IN (c:\temp\*.txt) DO cmd /c %0 process "%%f"
GOTO end
:processFile
SET IN=%2
perl -p -i.bak -e "s/change this/to this/g" %IN%
del %IN%.bak
GOTO end
:end
</c>
|