1

Could you please help me to retrieve file version property from Groovy script (in Windows platform)?

I mean the Version property available in Windows (7) in Details tab of file Properties window opened by right-click on file name.

I found to do it with WSH only.

Thanks In Advance!

ataylor
  • 64,891
  • 24
  • 161
  • 189
zubactik
  • 1,297
  • 3
  • 19
  • 34
  • see http://stackoverflow.com/questions/8828314/getting-file-attributes-in-java – moskiteau May 30 '13 at 19:36
  • @moskiteau in that post describes way to retrieve "simple" propeties. I found a lot of such solutions. But file version is "difficult" property to retrieve. I will try and describe Scriptom way. But it looks too heavy for my test deployment script. – zubactik Jun 19 '13 at 19:05

1 Answers1

0

First I tried to find a solution with and "More New I/O APIs for the Java™ Platform" (NIO.2) but didn't succeed. When I looked closer at your WSH-example I realized it is COM scripting.

So there are 2 possiblities to solve this:

An example for accessing Word from Java can be found here.

Update I tried to solve your problem, but run into an exception within the Namespace-function:

@Grab(group='net.java.dev.jna', module='platform', version='3.5.2')

import com.sun.jna.platform.win32.COM.COMException
import com.sun.jna.platform.win32.COM.COMObject
import com.sun.jna.platform.win32.OleAuto;
import com.sun.jna.platform.win32.Variant;
import com.sun.jna.platform.win32.Variant.VARIANT;
import com.sun.jna.platform.win32.WTypes.BSTR;
import com.sun.jna.platform.win32.WinNT.HRESULT;

public class Shell extends COMObject {

    public Shell() throws COMException {
        super("Shell.Application", false);
    }

    public HRESULT Namespace(String dir) throws COMException
    {
        def bstrDir = OleAuto.INSTANCE.SysAllocString(dir)
        def varDir = new VARIANT(bstrDir)
        def result = new VARIANT.ByReference()
        HRESULT hr = oleMethod(OleAuto.DISPATCH_METHOD, result, this.iDispatch, "Namespace", varDir);
    }
}

def shell = new Shell()
shell.Namespace("C:\\Temp")
ChrLipp
  • 15,526
  • 10
  • 75
  • 107