I've got a little script I'm using a paramter to pass in the current execution directory, but would like to make it a little more robust.

How does one find out the base execution directory?

2

3 Answers

Try this:

System.getProperty("user.dir"); 
3

Depending on the security model, if the System.getProperty(String) is not allowed, you can use

String currentDir = new File(".").getAbsolutePath() 
2

For reference:

The accepted answer on the question here is what I was looking for.

As an example, when calling c:\scripts\MyScript.groovy from c:\users\Scott\ I wanted to know c:\scripts\.

This is done via this:

def scriptDir = getClass().protectionDomain.codeSource.location.path

Where scriptDir is assigned something like:

/c:/scripts/MyScript.groovy

1