How do I get the list of files (or all *.txt files for example) in a directory in Scala. The Source class does not seem to help.
The JDK7 version, using the new DirectoryStream class is:
import java.nio.file.{Files, Path}
Files.newDirectoryStream(path)
.filter(_.getFileName.toString.endsWith(".txt"))
.map(_.toAbsolutePath)
Instead of a string, this returns a Path, which has loads of handy methods on it, like 'relativize' and 'subpath'.
Note that you will also need to import import scala.collection.JavaConversions._ to enable interop with Java collections.