I refer to question Add text to end of filename (but before extension) using batch file as I have the same problem. Using Windows 7 32-bit Enterprise (I know, I know ...) with all updates I wrote a tiny batch file pdfrename.bat
with only three lines:
a comment, starting with
REM
and no "hidden" continuation sign more to the right of the linethe proposed command, copy-pasted from the source as provided by @Karan, commented out with
REM
the adopted command for batch (doubling the
%
):REM Rework 2020-12-16 REM for %a in (*.txt) do ren "%~a" "%~na version 1%~xa" for %%F in (*.pdf) do ren "%%~F" "%%~nF OdB%%~xF"
Running the command (3.) from the command-prompt,
for %F in (*.pdf) do ren "%~F" "%~nF OdB%~xF"
works fine.
But executing the whole batch-file pdfrename.bat
from Windows explorer fails. Running the batch file from the command prompt pdfrename.bat
produces an error message syntax error:
Die folgende Verwendung des Pfadoperators zur Ersetzung eines Batchparameters
ist ungültig: %~na version 1%~xa"
[...]
You need not to understand German. The important point is that the error message refers to the commented out second line (2.), not to the third line!
I tried to retype REM
, inserted a tabulator after REM, inserted a second REM
after the first (REM REM ....
), inserted a third line after the second one with the same content and deleted the second line afterwards - nothing changed: the batch file terminates at the commented out second line with a syntax error. As soon as the incriminated second line is eliminated from the batch, the batch works fine.
I searched for "REM is ignored", but no luck, so I post the matter here. I never heard about or experienced before that the command processor tries at least to analyze a commented out line - and in the case that there is something wrong with the code after the comment-sign that it terminates the batch script.
REM to do the same in a command prompt, divide the number of variable calls, for ex: %%f , by two. ie, only have 1 percent sign instead of 2