Groovy检索文件版本属性(Windows)

时间:2013-05-30 05:36:11

标签: windows file properties groovy version

你能帮我从Groovy脚本(Windows平台)中检索文件版本属性吗?

我的意思是通过右键单击文件名打开文件属性窗口的详细信息标签中的Windows(7)中可用的版本属性。

我发现仅使用WSH进行此操作。

提前致谢!

1 个答案:

答案 0 :(得分:0)

首先,我试图找到一个解决方案和“更多用于Java™平台的新I / O API”(NIO.2),但没有成功。当我仔细研究你的WSH示例时,我意识到它是COM脚本。

因此有两种可能性来解决这个问题:

可以找到从Java访问Word的示例here

<强>更新 我试图解决你的问题,但在命名空间函数中遇到异常:

@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")
相关问题