Batch conversion with unoconv in Windows

I tried to use unoconv to convert all odg documents in a folder to svg but it just dies with “cannot find file”.
Is there something I am missing to able to do this?

python unoconv.py -f svg *.odg
unoconv: file '*.odg' does not exist.

It looks like the ‘*’ (asterisk) character was removed from my post somehow. I attempted to use wildcards with LibreOffice directly and then with unoconv but neither work in a Windows environment (specifically Win7 though I doubt that makes a difference).

Hi @MikeW1, I’ve updated the formatting in your post so that the asterisks are visible in the output.

I’m not sure about the unoconv.py script (is that file provided by LO?), but here’s how I convert Draw (odg) files to svg on the command line:

libreoffice -v --headless --convert-to svg test.odg

Note that if you already have LO running, that command will probably quit before doing any conversion for you. If you want to convert all odg files in a given directory, you can use a wildcard in your invocation like so:

libreoffice -v --headless --convert-to svg *.odg

I don’t know what exactly you are doing, what version of unoconv you are running, or why it failed. But it works perfectly on my system:

[dag@moria ~]$ unoconv -f svg test.odg 
[dag@moria ~]$ ls *.svg
test.svg
[dag@moria ~]$ file test.svg 
test.svg: SVG Scalable Vector Graphics image

It also works using wildcards:

[dag@moria ~]$ rm -f test.svg
[dag@moria ~]$ unoconv -f svg *.odg 
[dag@moria ~]$ ls *.svg
test.svg
[dag@moria ~]$ file test.svg 
test.svg: SVG Scalable Vector Graphics image

I am using unoconv v0.5 and LibreOffice 3.4.5, so it should work !

It appears that Windows understands wildcards in a different way than Linux and so LibreOffice or even Python cannot utilize ("*.odg") in Windows without using the “glob” module. (It seems that Python’s implementation of OS recognizes *.odg as a literal filename in Windows instead of a wildcard).

To solve this, I had to write a wrapper like the following:

matches = []
for root, dirnames, filenames in os.walk(os.getcwd()):
  for filename in fnmatch.filter(filenames, '*.odg'):
      matches.append(os.path.join(root, filename))

os.system("unoconv.py -f svg " + " ".join(matches))

I hope that helps others who encounter this same problem.

Makes sense. On Unix it is the shell that expands wildcards not the tool, on Windows it’s probably the tool that expands wildcards and we may have to improve unoconv to also accept wildcards. So it’s not exactly a bug. If you care about this functionality in unoconv, feel free to open an issue !