Looks like you could pretty much use Files as an extension module and/or
category for Path...
Hang on, does it work?
groovy> import java.nio.file.*
groovy> use (Files) {
groovy> Path p = Path.of("src/groovy")
groovy> println "is directory? ${p.isDirectory()}"
groovy> p.list().each { println "${it}: ${it.getOwner()}
${it.getPosixFilePermissions()}" }
groovy> }
is directory? true
src/groovy/benchmark: rachel [OWNER_WRITE, OTHERS_READ, OWNER_EXECUTE,
GROUP_READ, GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_READ]
src/groovy/xdocs: rachel [OWNER_WRITE, OTHERS_READ, OWNER_EXECUTE, GROUP_READ,
GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_READ]
src/groovy/bootstrap: rachel [OWNER_WRITE, OTHERS_READ, OWNER_EXECUTE,
GROUP_READ, GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_READ]
src/groovy/LICENSE: rachel [OWNER_WRITE, OTHERS_READ, GROUP_READ, OWNER_READ]
...
oh yeah that works 😉
--
Rachel Greenham
[email protected]
> On 15 Oct 2021, at 15:57, Nelson, Erick <[email protected]> wrote:
>
> import java.nio.file.Path
> import java.nio.file.Files
>
> File f = new File('test')
> Path p = f.toPath()
> Files.isReadable(p) // boolean
> Files.isWritable(p) // boolean
> Files.isExecutable(p) // boolean
> Files.isDirectory(p) // boolean
> Files.isRegularFile(p) // boolean
>
>
> From: James McMahon <[email protected]>
> Date: Friday, October 15, 2021 at 4:50 AM
> To: [email protected] <[email protected]>
> Subject: Checking directory state using Groovy
>
> Hello. I am trying to convert an existing script from python to Groovy. It
> executes a number of os.path and os.access commands, which I've not yet been
> able to find examples of that are written in Groovy. I have found similar
> implementations that employ "add on" Jenkins libraries for Groovy, but I will
> not have access to such libraries.Here is a brief excerpt from what I now do
> in python. Has anyone done similarly in Groovy? Can I impose for an example?
>
> Thanks very much in advance. Here is my python:
>
> if ( os.path.exists(result['thisURL']) and os.path.isfile(result['thisURL'])
> ) :
> if ( os.access(result['thisURL'], os.F_OK)
> and os.access(result['thisURL'], os.R_OK)
> and os.access(thisDri, os.W_OK)
> and os.access(thisDir, os.X_OK) ) :
> # do some stuff
> else :
> # dir and file not accessible, do some different stuff