I have to run a tool from libreoffice i.e. soffice
to convert doc/docx to PDF files.
It works well. But I don't want to convert them again and again. So I need a if check to determine if the file.
So, I am stuck with following :
- After getting filename how can I replace the extension from .doc or .docx to pdf.
- After renaming how to check if the file exists or not.
I have tried until this :
@echo off
for %%f in (*.doc*) do (
if "%%~xf"==".doc" (
echo %%f
set str = %%f
call :strLen str strlen
echo String is %strlen% characters long
soffice --headless --convert-to pdf:writer_pdf_Export --outdir . "%%f"
)
if "%%~xf"==".docx" (
echo %%f
soffice --headless --convert-to pdf:writer_pdf_Export --outdir . "%%f"
)
)
:strLen
setlocal enabledelayedexpansion
:strLen_Loop
if not "!%1:~%len%!"=="" set /A len+=1 & goto :strLen_Loop
(endlocal & set %2=%len%)