1

I have the following groovy cod to display in Active Choice Parameter some folder names and if the folder contains the ".a7" file display the file, if not,should post a error message. My problem is that my cod don't display the error message if the folder "a7.nativ" is missing and implicit the path to ".a7" file(/mnt/a7/v5.5/a7.nativ/v5.5/55.a7) is interrupted. Can somebody help me please? This is the cod:

 Build=[] path2 = "/mnt/cc7/v5.5/a7.nativ/v5.5/" new File(path2).eachFileMatch(~/.*.a7/) { Build.add(it.getName()) } if(Build){ return Build } else { return ["There is no file to display"] } 

1 Answer 1

1

You need an additional step that checks if given path exists. Otherwise, you implicitly assume that the given folder always exists. Consider the following modification:

def build = [] def path2 = "/mnt/cc7/v5.5/a7.nativ/v5.5/" def file = new File(path2) if (!file.exists()) { return ["There is no file to display"] } file.eachFileMatch(~/.*.a7/) { build.add(it.getName()) } return build ?: ["There is no file to display"] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.