识别文件类型的最佳方法是 groovy 中的可执行文件
Best way to identify the file type is executable in groovy
我有一个路径变量,想检查给定路径是否是可执行文件
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"
}
通过上面的代码,我能够确定该文件是否可执行。但只是想知道是否还有其他方法可以找出 groovy
中的文件类型
def file = new File('/abc/xyx/abcd.sh')
println file.canExecute()
我有一个路径变量,想检查给定路径是否是可执行文件
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"
}
通过上面的代码,我能够确定该文件是否可执行。但只是想知道是否还有其他方法可以找出 groovy
中的文件类型def file = new File('/abc/xyx/abcd.sh')
println file.canExecute()