You need to use delayed expansion if you are going to define and expand a variable within a FOR loop. You properly enabled delayed expansion, but you need to use set K=!J:~0,-1!
instead of set K=%J:~0,-1%
. Also use "d:\docsfinal!K!"
.
But there is a better (simpler) way that avoids delayed expansion :-)
for /R d:\docs %%I in (*) do for /f "eol=: delims=" %%J in ("%%I\..") do (
soffice --headless --convert-to docx:"MS Word 2007 XML" --outdir "d:\docsfinal%%~pnxJ" "%%I"
)
Or even better yet, I think the following will work (simply append a dot to the path). But I haven't tested this.
for /R d:\docs %%I in (*) do (
soffice --headless --convert-to docx:"MS Word 2007 XML" --outdir "d:\docsfinal%%~pI." "%%I"
)