Using the --convert-to command-line function to convert formats under Windows 10
We will consider the .docx to .odt conversion, but the syntax and steps are the same for other formats supported by LibreOffice.
On MS-Windows 10 we can use a command like soffice.exe --convert-to odt my_document.docx in order to convert my_document.docx from the MS docx format to the open document format (odt). The --convert-to function allows us to specify a set of documents by using the general wildcard syntax for files. For example, it is legal to use *.docx when you have a bunch of .docx files to convert from the current directory.
But when used in the Windows Command shell, it does not work at all. It seems that all the conversions are started simultaneously, and since two instances of LibreOffice (soffice.exe) cannot run at the same time when launched from the command line, the process will never end. At best, you will end with one or two files converted, but in any case, you will have to kill manually a bunch of LibreOffice processes hung in the system (twice as much as the number of files found, at first sight).
To overcome this, a simple way is to use the new Windows Subsystem for Linux Environment provided by MS for its version 10 of Windows. You may have to install it, what is quite straightforward if you follow the documentation here https://docs.microsoft.com/en-us/windows/wsl/install-win10.
Once done, you will have access to quite a nice bash shell running on top of the base Windows-system, and the --convert-to function will work properly, in a synchronous mode.
- Identify the path to soffice.exe.
- cd to the directory containing the files to convert, after having created a destination directory.
- Give this command : <path to soffice.exe> --convert-to odt --outdir <my_output_directory> *.docx
"/mnt/c/Program Files/LibreOffice 5/program/soffice.exe" --convert-to odt --outdir ./Converted_To_odt *.docx will convert the docx files from the current directory to their equivalent into the ./Converted_To_odt subdirectory.
The WSL mounts a complete file system on its own. So, the syntax to specify a file location in the directory tree is different from the Windows one. The first difference is the root point : Under Windows it uses to be C:\, the equivalent in the bash shell is /mnt/c/. Than, the token separator under Windows is \, in the bash it is the / Unix one. For the rest, the rules are the same, the bash shell supports the same character set as the Windows command shell as well as long filenames and filenames with spaces, provided that they are delimited by double-quotes (").
How to create the command ?
The easiest way is to examine the shortcut you use every time you start LibreOffice. Right-click on it, than "Properties", than copy the "Target" field content. In the example given, it will be "C:\Program Files\LibreOffice 5\program\soffice.exe". Then adjust the syntax to the bash requirements as described before, to get this : "/mnt/c/Program Files/LibreOffice 5/program/soffice.exe" Beware, Unix is case-sensitive, Windows is not.
For the rest, you are done.
Using the bash shell on Windows is an easy way to convert a bunch of files from a format to another using LibreOffice builtin command-line function. It works quietly.
Or the Simplest way, interactive
It is even simpler to use the builtin LibreOffice Document converter Assistant, as described here: https://help.libreoffice.org/latest/en-US/text/shared/autopi/01130000.html.
You can start it by clicking in the Menu Files - Assistants - Document Converter...
Some user has reported that he had to cut its files lot in bunches of 200 pieces because the process crashed sometimes.
Or the actual description
The problem is not "all the conversions are started simultaneously" and everything. It's simply that LibreOffice's
--convert-to in fact does not support using wildcards itself, and only works on non-Windows systems because they process the wildcards in their shells (and of course, these shells also work on Windows, like with Cygwin or WSL).
What does this mean? This means that in Bash, when you send a command like
soffice --convert-to odt path/to/*.doc, the command is first analyzed by Bash, and it finds the
path/to/*.doc there, and enumerates every file that matches the mask, puts their names into one string, and substitutes the
path/to/*.doc with something like
path/to/1.doc path/to/2.doc path/to/345.doc. This is what LibreOffice sees.
Windows' cmd.exe does not do that, and sends the
path/to/*.doc to LibreOffice unmodified. LibreOffice simply tries to open the file named
*.doc, and fails. That's all.
In Windows' cmd.exe, the pre-processing should be done explicitly, like this:
for %f in ("path\to\*.doc") do "C:\Program Files\LibreOffice\program\soffice" --convert-to odt "%f"
The enhancement request to implement own wildcard processing is tdf#48413.