
I am trying to recursively find all docx files in a folder (with subfolders) and convert them to pdf using a headless LibreOffice instance. I’d like the output file to be saved in the same folder as the input file. Unfortunately, the output file is always saved in the current directory.
How can I save the output file in the same directory in which the input file was located?
Here are the commands that I have tried:
find . -type f -name '*.docx' -print -exec sh -c '/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf "{}"' ;
I thought it might work by using the --outdir
option but the files still get saved in the current working directory.
find . -type f -name '*.docx' -print -exec sh -c '/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir . "{}"' ;