How can use array to imitate repeated individual instances? I'm working an example to list directory contents. When I process each directory the code works. Now I'd like to put both directories in an array and iterate the array. I get an error when I declare 'dir_c' because I've not given it a directory name which will change.

  def outfile = new File('Y:/TEMP/dirlist.txt')
  def dir_a = new File('z:/pathA/pathB')
  def dir_b = new File('z:/pathA/pathQ')
  // def dir_c = new File() //causes error ==&gt;Could not find which method &lt;init&gt;(to invoke from this list
outfile.write('')

 dir_a.eachFile {
  if (it.isFile()) {
  outfile.append(it.name + '\n')
  }

  dir_b.eachFile {
   if (it.isFile()) {
    outfile.append(it.name + '\n')
   }
  // Up to this point code works

   def searchDir = ["z:/pathA/pathB","z:/pathA/pathQ"]
   searchDir.each{
  //was thinking using  ==&gt;dir_c = it 
  // then carry on like singleton cases
  // but I get error message when I declare dir_c
  }
Do you mean like this:

def searchDir = ["z:/pathA/pathB","z:/pathA/pathQ"]
searchDir.each { d -&gt;
    new File( d ).eachFile {
        if (it.isFile()) {
            outfile.append( "$it.name\n" )
        }
    }
}