title: Groovy (File IO): find all files and return all files - the Groovy way
body: <p>Ok, this should be easy...</p>
  
  <p>I'm new to groovy and I'm looking to implement the following logic:</p>
  
  <pre><code>def testFiles = findAllTestFiles();
  </code></pre>
  
  <p>So far, I've come up with the code below which successfully prints all files names.  However, instead of printing, I just need to put them into a collection.  Of course, I could do this the old java way: just instantiate a collection, add all the elements and return it.  However, that wouldn't teach me anything.</p>
  
  <p>So how do you do this the cool, "Groovy" way?</p>
  
  <pre><code>static File[] findAllTestFiles() {
      def directory = new File("src/test/java");
      def closure = {File f -&gt; if(f.name =~ /Test\.java$/) println f }
      directory.eachFileRecurse FileType.FILES, closure
      return null;
  }
  </code></pre>
  
  <p>I'm looking to implement <em>findAlltestFiles()</em> in Groovy using as little code as possible while still being readable.</p>