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")