Skip to content

Instantly share code, notes, and snippets.

@osima
Created October 10, 2010 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osima/619059 to your computer and use it in GitHub Desktop.
Save osima/619059 to your computer and use it in GitHub Desktop.
ディレクトリを走査して特定のファイルを抽出
// g100pon #23 ディレクトリを走査して特定のファイルを抽出
//
// 例 : カレントディレクトリ以下にある htmlファイル を列挙
// groovy findfile '.*.html'
//
if( args.length<1 ){
println 'Usage: groovy findfile regex'
System.exit(0)
}
regex = args[0]
recur = {
if( it.isDirectory() )
it.listFiles().each{ recur(it) }
else
if( java.util.regex.Pattern.compile(regex).matcher( it.name ).find() )
println it.canonicalPath
}
recur(new File('.'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment