0

I have a path variable and wanted to check given path is executable file or not

           boolean isExecutable = false
            def process = ("file " + "/abc/xyx/abcd.sh").execute()
            log.info("printing the output: ")
            process.text.eachLine {
                if (it.contains("executable")) {                   
                    isExecutable = true
                } 
            }

if(isExecutable){
println "file is executable"
}

With the above code I am able to find out whether that file is executable or not. But just wanted to know that is there any other alternatives to find out the file type in groovy

Raju
  • 123
  • 1
  • 14

1 Answers1

3
def file = new File('/abc/xyx/abcd.sh')
println file.canExecute()
Evgeny Smirnov
  • 2,886
  • 1
  • 12
  • 22
  • Thanks for the answer.But in case if we pass a directory instead of the file then that case this is giving true for example path is '/abc/xyx' in this case also it is returning true. – Raju Dec 13 '17 at 13:29
  • 2
    do `file.isFile() && file.canExecute()` then – tim_yates Dec 13 '17 at 13:49