Skip to content

Instantly share code, notes, and snippets.

@kazua
Created November 9, 2012 15:32
Show Gist options
  • Save kazua/4046329 to your computer and use it in GitHub Desktop.
Save kazua/4046329 to your computer and use it in GitHub Desktop.
ファイル検索(ファイル名)
import java.io._
object filesearch {
def filesearch(path : String, schwds : String){
try{
new File(path).listFiles.map{
case d if d.isDirectory() => filesearch(d.getPath(), schwds)
case f if f.isFile() && f.getName().contains(schwds) => println(f.getPath())
case e => e
}
}catch{
case ex : java.lang.NullPointerException => println("%s:%s".format(path, "検索不可ディレクトリです"))
case ex2 : java.io.IOException => println("%s:%s".format(path, "ファイルにアクセスできません"))
}
}
def main(args: Array[String]) {
filesearch(args(0), args(1))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment