Bug 48413 - Windows: Command line bulk conversion including wildcards (*?) not working
Summary: Windows: Command line bulk conversion including wildcards (*?) not working
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
(earliest affected)
Inherited From OOo
Hardware: All Windows (All)
: low enhancement
Assignee: Not Assigned
Whiteboard: BSA
Keywords: difficultyBeginner, easyHack, skillCpp
: 68647 (view as bug list)
Depends on:
Blocks: Commandline
  Show dependency treegraph
Reported: 2012-04-07 05:20 UTC by zumbs
Modified: 2020-07-07 03:37 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description zumbs 2012-04-07 05:20:38 UTC
Problem description: 

The LibreOffice executable (soffice.exe) supports a number of command line arguments as described in http://help.libreoffice.org/Common/Starting_the_Software_With_Parameters. The linked document (as well as blog posts on the internet) suggests that it should be possible to use the command line to convert all MS Word documents in a directory to odf. However, following command line does not convert anything:

soffice.exe --headless --convert-to odf --outdir C:\Docs\Out C:\Docs\In\*.doc

If the direct path is used, e.g.

soffice.exe --headless --convert-to odf --outdir C:\Docs\Out C:\Docs\In\a.doc

the specified document is converted to a.odf and placed in the out directory.

I run Windows 7 64 bit and have LibreOffice installed. I have made sure that no instance of soffice is running before trying to use the command line.

Steps to reproduce:
1. Open command prompt to C:\Program Files (x86)\LibreOffice 3.5\program
2. Enter >soffice.exe --headless --convert-to odf --outdir C:\Docs\Out C:\Docs\In\*.doc
3. The documents in C:\Docs\In are not converted.
4. Enter >soffice.exe --headless --convert-to odf --outdir C:\Docs\Out C:\Docs\In\a.doc
5. The specified document, a.doc, is found in C:\Docs\Out.

Current behavior:
Using *.doc does not convert any documents in the input directory.

Expected behavior:
Using *.doc converts all documents in the input directory and copy the result to the output directory. Preferably, it would also iterate through sub directories, maintaining the directory structure in the outdir, but I'm unsure if that is the intended behaviour.

Platform (if different from the browser): 
Browser: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
Comment 1 Nino 2012-04-21 14:05:38 UTC Comment hidden (off-topic)
Comment 2 zumbs 2012-04-22 02:03:09 UTC
I installed LibreOffice 3.5.1rc1 and tried out the following command line argument:

C:\Docs\In>for %i in (*.doc) do soffice.exe --headless --convert-to odf --outdir C:\Docs\Out %i


C:\Docs\In>soffice.exe --headless --convert-to odf --outdir C:\Docs\Out File1.doc

C:\Docs\In>soffice.exe --headless --convert-to odf --outdir C:\Docs\Out File2.doc

C:\Docs\In>soffice.exe --headless --convert-to odf --outdir C:\Docs\Out File3.doc

The first file was correctly converted, but conversion of subsequent files failed. It would seem that Windows starts the three calls in parallel, which causes us to run into the bug where the command line fail to succeed if LibreOffice is already running (bug 37531). I saw a lot of instances of soffice.exe and soffice.bin in Taskmanager.

I tried using an Ubuntu 11.04 live cd. With command line arguments similar to the one in my original bug report, I got full conversion of the contents of C:\Docs\In, so it seems like it is a Windows bug.

On a side note, I made a small .net tool to convert the files one at a time, so I no longer need a workaround.
Comment 3 QA Administrators 2015-01-02 16:58:07 UTC Comment hidden (obsolete)
Comment 4 zumbs 2015-01-11 16:46:12 UTC
Verified that bug is still present with LibreOffice running on Windows 7 SP1 64 bit. (Note that as per the comments above, the issue is not present on Linux, but I have not verified that again.)
Comment 5 Maxim Monastirsky 2015-07-31 11:36:11 UTC
*** Bug 68647 has been marked as a duplicate of this bug. ***
Comment 6 QA Administrators 2016-09-20 10:21:07 UTC Comment hidden (obsolete)
Comment 7 zumbs 2016-09-20 17:12:10 UTC
Bug is still present with LibreOffice on Windows 7 SP1 64 bit. As before, I have not investigated Linux. No change in behavior.
Comment 8 QA Administrators 2017-10-23 14:11:28 UTC Comment hidden (obsolete)
Comment 9 Ljubomir Ljubojevic 2018-09-28 10:07:29 UTC
This bug is still present on LibreOffice for Windows x86.

I am seeing this problem for years, and ONLY on Windows, when wildcard "*" is used.

*.doc will NOT work
<filename>.doc will always work.

Convert files using LibreOffice on Linux
Comment 10 QA Administrators 2019-09-30 02:51:50 UTC Comment hidden (obsolete)
Comment 11 zumbs 2019-09-30 18:07:54 UTC
I have tested the bug with (x64) on Windows 10 Pro x64 Version	10.0.18362 Build 18362 and the bug has not been fixed..
Comment 12 jhack_jos 2020-04-29 10:05:03 UTC
I can confirm on LibreOffice version (x64) for Windows 10 Pro x64 the bug is still there. Wildcards should be definitely handled nicely by the soffice executable in headless mode.

Example of not working command:
"C:\Program Files\LibreOffice\program\soffice.exe" -ArgumentList "--headless --convert-to pdf *.odt

Workaround: if anyone is in search of a temporary solution, you may use a powershell or batch script. Here is a simple example Powershell script I wrote to convert all odt documents inside a folder to pdf:

Get-ChildItem *.odt | Foreach {
  Write-Host "Converting `"$_`" ..."
  Start-Process -Wait -FilePath "C:\Program Files\LibreOffice\program\soffice.exe" -ArgumentList "--headless --convert-to pdf `"$_`""

You may:
- change "Get-ChildItem *.odt" to your favourite input format. Ex. "Get-ChildItem *.docx"
- add -Recurse to it if you need to convert files in nested folders. Ex. "Get-ChildItem *.odt -Recurse"
- change "--convert-to pdf" to your needed output format. Ex. "--convert-to docx"

Hope this issue gets addressed.
Good luck everyone!
Comment 13 jhack_jos 2020-04-29 10:08:50 UTC
It seems you cannot edit a post on Bugzilla.
I did a small mistake when I copy&pasted the example command.

Here is a correct example of command not working:
"C:\Program Files\LibreOffice\program\soffice.exe" --headless --convert-to pdf *.odt
Comment 14 Mike Kaganski 2020-07-06 05:35:13 UTC
This Windows-only enhancement needs LibreOffice to implement own wildcard matching when pre-processing the passed command line on Windows. Unlike *nix environment, On Windows there's no shell pre-processing that the resulting command line that LibreOffice gets is already expanded.

For now, tricks like

> for %%f in ("input folder\*.sxd") do "C:\Program Files\LibreOffice\program\soffice.exe" --convert-to png --outdir "output folder" "%%f"

are needed (the example above is for batch files; if using in console, %% should be replaced into %; see e.g. [1]).

Code pointer: the command line handling happens in desktop/source/app/cmdlineargs.cxx. It must be Windows-only, since on other platforms, the file path is an arbitrary byte sequence, which itself may include bytes like '*' or '?' (different flavors of FS may apply own restrictions).

[1] https://ask.libreoffice.org/en/question/86800