view chapter9/FileMatcher.scala @ 0:b316eec6fa7a draft default tip

add sample files
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 08 Jan 2013 16:41:46 +0900
parents
children
line wrap: on
line source

object FileMatcher {
     private def filesHere = (new java.io.File(".")).listFiles
    /*
     def filesEnding(query: String) =
     for (file <- filesHere; if file.getName.endsWith(query))
     yield file
     def filesContaining(query: String) =
     for (file <- filesHere; if file.getName.contains(query))
     yield file
     def filesRexex(query: String) = 
     for (file <- filesHere; if file.getName.matches(query))
     yield file
     */
    def filesMatching(query: String,
		      matcher: (String, String) => Boolean) = {
			  for (file <- filesHere; if matcher(file.getName, query))
			  yield file
		      }
    def filesEnding(query: String) =
	filesMatching(query, _.endsWith(_))
    def filesContaining(query: String) =
	filesMatchin(query, _.contains(_))
    def filesRegex(query: String) =
	filesMatching(query, _.matches(_))
}