I want to remove a known string .doc
from the middle of a variable string %%f
in a loop.
I have a batch file that converts a Word file to PDF:
echo Converting MS Word documents to PDF . . .
cd /D "%mypath%\documents"
for /f "delims=|" %%f in ('dir *.doc /S /B') do ( Q:\OfficeToPDF.exe "%%f" "%%f.pdf" )
Problem: The output files are named myfile.doc.pdf
where I don't know the length of myfile
in advance.
--> How can I remove .doc
from that string?
Alternatively, replace .doc.
with .
would achieve the same goal.
I think I need this kind of string substitution but I can't get it to work within that for
loop.
It would almost be like this, but it doesn't work:
for [...] do ( set outname=%%f:.doc.=.% && Q:\OfficeToPDF.exe "%%f" "%outname%" )
I've seen this and this (as well as many other questions) but I didn't see a solution that works in a loop. I found a Linux solution for it but that doesn't directly help me.